提交 1f3b5458 编写于 作者: L Lijun Fang 提交者: Xie XiuQi

mm: Be allowed to alloc CDM node memory for MPOL_BIND

euler inclusion
category: feature
bugzilla: 11082
CVE: NA
-----------------

CDM nodes should not be part of mems_allowed, However,
It must be allowed to alloc from CDM node, when mpol->mode was MPOL_BIND.
Signed-off-by: NLijun Fang <fanglijun3@huawei.com>
Reviewed-by: Nzhong jiang <zhongjiang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 ed485a0a
...@@ -204,10 +204,6 @@ extern unsigned int kobjsize(const void *objp); ...@@ -204,10 +204,6 @@ extern unsigned int kobjsize(const void *objp);
#define VM_NORESERVE 0x00200000 /* should the VM suppress accounting */ #define VM_NORESERVE 0x00200000 /* should the VM suppress accounting */
#define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */ #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
#ifdef CONFIG_COHERENT_DEVICE
#define VM_CDM 0x00800000 /* Contains coherent device memory */
#endif
#define VM_SYNC 0x00800000 /* Synchronous page faults */ #define VM_SYNC 0x00800000 /* Synchronous page faults */
#define VM_ARCH_1 0x01000000 /* Architecture-specific flag */ #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
#define VM_WIPEONFORK 0x02000000 /* Wipe VMA contents in child. */ #define VM_WIPEONFORK 0x02000000 /* Wipe VMA contents in child. */
...@@ -224,6 +220,10 @@ extern unsigned int kobjsize(const void *objp); ...@@ -224,6 +220,10 @@ extern unsigned int kobjsize(const void *objp);
#define VM_NOHUGEPAGE 0x40000000 /* MADV_NOHUGEPAGE marked this vma */ #define VM_NOHUGEPAGE 0x40000000 /* MADV_NOHUGEPAGE marked this vma */
#define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */ #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
#ifdef CONFIG_COHERENT_DEVICE
#define VM_CDM 0x100000000 /* Contains coherent device memory */
#endif
#ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS #ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
#define VM_HIGH_ARCH_BIT_0 32 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_0 32 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_1 33 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_1 33 /* bit only usable on 64-bit architectures */
......
...@@ -881,13 +881,17 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) ...@@ -881,13 +881,17 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid)
} }
static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, int nid, static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, int nid,
nodemask_t *nmask) nodemask_t *nmask, struct mempolicy *mpol)
{ {
unsigned int cpuset_mems_cookie; unsigned int cpuset_mems_cookie;
struct zonelist *zonelist; struct zonelist *zonelist;
struct zone *zone; struct zone *zone;
struct zoneref *z; struct zoneref *z;
int node = -1; int node = -1;
bool mbind_cdmnode = false;
if (is_cdm_node(nid) && mpol != NULL && mpol->mode == MPOL_BIND)
mbind_cdmnode = true;
zonelist = node_zonelist(nid, gfp_mask); zonelist = node_zonelist(nid, gfp_mask);
...@@ -896,7 +900,8 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, ...@@ -896,7 +900,8 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,
for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nmask) { for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nmask) {
struct page *page; struct page *page;
if (!cpuset_zone_allowed(zone, gfp_mask)) if (!cpuset_zone_allowed(zone, gfp_mask) &&
mbind_cdmnode == false)
continue; continue;
/* /*
* no need to ask again on the same node. Pool is node rather than * no need to ask again on the same node. Pool is node rather than
...@@ -951,7 +956,7 @@ static struct page *dequeue_huge_page_vma(struct hstate *h, ...@@ -951,7 +956,7 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
gfp_mask = htlb_alloc_mask(h); gfp_mask = htlb_alloc_mask(h);
nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask); nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask);
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask); page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask, mpol);
if (page && !avoid_reserve && vma_has_reserves(vma, chg)) { if (page && !avoid_reserve && vma_has_reserves(vma, chg)) {
SetPagePrivate(page); SetPagePrivate(page);
h->resv_huge_pages--; h->resv_huge_pages--;
...@@ -1638,7 +1643,7 @@ struct page *alloc_huge_page_node(struct hstate *h, int nid) ...@@ -1638,7 +1643,7 @@ struct page *alloc_huge_page_node(struct hstate *h, int nid)
spin_lock(&hugetlb_lock); spin_lock(&hugetlb_lock);
if (h->free_huge_pages - h->resv_huge_pages > 0) if (h->free_huge_pages - h->resv_huge_pages > 0)
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, NULL); page = dequeue_huge_page_nodemask(h, gfp_mask, nid, NULL, NULL);
spin_unlock(&hugetlb_lock); spin_unlock(&hugetlb_lock);
if (!page) if (!page)
...@@ -1657,7 +1662,8 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, ...@@ -1657,7 +1662,8 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
if (h->free_huge_pages - h->resv_huge_pages > 0) { if (h->free_huge_pages - h->resv_huge_pages > 0) {
struct page *page; struct page *page;
page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask); page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid,
nmask, NULL);
if (page) { if (page) {
spin_unlock(&hugetlb_lock); spin_unlock(&hugetlb_lock);
return page; return page;
......
...@@ -485,6 +485,10 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, ...@@ -485,6 +485,10 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
#define ALLOC_CPUSET 0x40 /* check for correct cpuset */ #define ALLOC_CPUSET 0x40 /* check for correct cpuset */
#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */ #define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
#ifdef CONFIG_COHERENT_DEVICE
#define ALLOC_CDM 0x100
#endif
enum ttu_flags; enum ttu_flags;
struct tlbflush_unmap_batch; struct tlbflush_unmap_batch;
......
...@@ -248,6 +248,9 @@ static int mpol_set_nodemask(struct mempolicy *pol, ...@@ -248,6 +248,9 @@ static int mpol_set_nodemask(struct mempolicy *pol,
nodes_and(nsc->mask1, nodes_and(nsc->mask1,
cpuset_current_mems_allowed, node_states[N_MEMORY]); cpuset_current_mems_allowed, node_states[N_MEMORY]);
#ifdef CONFIG_COHERENT_DEVICE
nodes_or(nsc->mask1, cdmmask, nsc->mask1);
#endif
VM_BUG_ON(!nodes); VM_BUG_ON(!nodes);
if (pol->mode == MPOL_PREFERRED && nodes_empty(*nodes)) if (pol->mode == MPOL_PREFERRED && nodes_empty(*nodes))
nodes = NULL; /* explicit local allocation */ nodes = NULL; /* explicit local allocation */
...@@ -1776,7 +1779,8 @@ static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy) ...@@ -1776,7 +1779,8 @@ static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)
/* Lower zones don't get a nodemask applied for MPOL_BIND */ /* Lower zones don't get a nodemask applied for MPOL_BIND */
if (unlikely(policy->mode == MPOL_BIND) && if (unlikely(policy->mode == MPOL_BIND) &&
apply_policy_zone(policy, gfp_zone(gfp)) && apply_policy_zone(policy, gfp_zone(gfp)) &&
cpuset_nodemask_valid_mems_allowed(&policy->v.nodes)) (cpuset_nodemask_valid_mems_allowed(&policy->v.nodes) ||
nodemask_has_cdm(policy->v.nodes)))
return &policy->v.nodes; return &policy->v.nodes;
return NULL; return NULL;
......
...@@ -3301,7 +3301,11 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, ...@@ -3301,7 +3301,11 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
if (cpusets_enabled() && if (cpusets_enabled() &&
(alloc_flags & ALLOC_CPUSET) && (alloc_flags & ALLOC_CPUSET) &&
!__cpuset_zone_allowed(zone, gfp_mask)) !__cpuset_zone_allowed(zone, gfp_mask)
#ifdef CONFIG_COHERENT_DEVICE
&& !(alloc_flags & ALLOC_CDM)
#endif
)
continue; continue;
/* /*
* When allocating a page cache page for writing, we * When allocating a page cache page for writing, we
...@@ -4343,8 +4347,12 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, ...@@ -4343,8 +4347,12 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,
*alloc_mask |= __GFP_HARDWALL; *alloc_mask |= __GFP_HARDWALL;
if (!ac->nodemask) if (!ac->nodemask)
ac->nodemask = &cpuset_current_mems_allowed; ac->nodemask = &cpuset_current_mems_allowed;
else else {
*alloc_flags |= ALLOC_CPUSET; *alloc_flags |= ALLOC_CPUSET;
#ifdef CONFIG_COHERENT_DEVICE
*alloc_flags |= ALLOC_CDM;
#endif
}
} }
fs_reclaim_acquire(gfp_mask); fs_reclaim_acquire(gfp_mask);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册