From patchwork Mon Feb 18 21:07:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8A496CB for ; Mon, 18 Feb 2019 21:07:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C645F2BC8A for ; Mon, 18 Feb 2019 21:07:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B91122BCBE; Mon, 18 Feb 2019 21:07:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB79E2BC8A for ; Mon, 18 Feb 2019 21:07:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 938AE8E0004; Mon, 18 Feb 2019 16:07:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 911128E0002; Mon, 18 Feb 2019 16:07:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B0588E0004; Mon, 18 Feb 2019 16:07:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 296938E0002 for ; Mon, 18 Feb 2019 16:07:29 -0500 (EST) Received: by mail-wr1-f70.google.com with SMTP id j16so6743596wrp.4 for ; Mon, 18 Feb 2019 13:07:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=eTq9HjBTOU/jc5MhAmF8ieTxY15GS5mv/p78sMj8zOY=; b=pSbGjTxSaVnZnDNBVmiOsj7ZvXIXOoB7Xl585Db2eZ5yBsbuMMkkbOxrpqlKNyZtcb 7pZud7jveKSjRKwKaqgxCH52AGpzSB6efXzat7XE9BIaCEE1FBLThPdhdcKQHh1FIFkg it3HdfVCDFdiqIWtZtfVO7rv3oAi/FF2zfoQZa4USL2gn9eEydfUCwN7C1UJEiUYSW3N v5Xyb8iztM2c9bOIDwQ1e56bc2eWHJj//+Q963YKnFA898CK9I42q3kXs36m/NRIWTKb dSbXIIowqhc4JHI2PErSa2004j/iOxMhSfxrVfr7oxu7Si6Eh5nEbSSEX19iRP4QpMcK FW3g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAuanfT2lJEr3z2d29KVPi6qks5dY099aInoXH++EhMNLPRPL41nZ r6H3kNgCfVEdtNiNTJoBmPP9fpB93FVirXVzGmQ+sYpY5RjluFPG1a3gfw1CvBrFNfCNan+5gBv 3PQSjAYYxvb67iNVGpngJODRhCItO9hy0Q1WnchzxvfdlJ5Po0QQqAuGuDKYvK5Gpng== X-Received: by 2002:a1c:eb0a:: with SMTP id j10mr449183wmh.115.1550524048643; Mon, 18 Feb 2019 13:07:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IYnCrW5epgoki43i0ZoylVupeg7VoeCLNBxj8P+BTnYe1bK+ww29WUGs+qJO9ozpYuGgBzu X-Received: by 2002:a1c:eb0a:: with SMTP id j10mr449149wmh.115.1550524047444; Mon, 18 Feb 2019 13:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524047; cv=none; d=google.com; s=arc-20160816; b=vT/yZ3RHDsS9HI9UGp1NpLDeo7NN420U5weQvPBA5s/A2GR0vRY7Z6Xil8S8eWrs5m sWlMNBYTg0tyWmhRnuuL1GRYW+k9Gwa4XJ8aR7TJeIjbhT44KKjvuuebwGKm5mvp3Jwv YDik1BpBDQPGWx0Ax+v/WDBTit2lf3C2aVoSuTE+6PAMtf2M1lT0NhhV4OnnXMdzkXDE l6OTvs18XR8jtuP/e+7Mj022qXJDTMSMEreJSPvSsj6FHC4rAw5X8Z9kfO4XcK21Pmr6 RQ2KMNFz/DTiF65V4QcnM0BP2WZUcrsZIitMRBjGbnVclcIqu67pNh8vNeBmqWaRPVry toKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=eTq9HjBTOU/jc5MhAmF8ieTxY15GS5mv/p78sMj8zOY=; b=KdJHmrsIRguFjym7h6W1nhlgNKEYQvkOi/PfbBKyt5eUkd04nNfsJ8dyPVkx/DqQ/k XN89vKMmEl2qKYxNkUvI78K1q89w52hgJWcRkA6nVjk9ATo+cFCZzkFP1BsOIngM3jec qTGF5eA5ZTphHojkf5+wSbt0z8/Fw/bGCvnpv24Rk59RONMxyXz2uIl9p089Rb8PsI7w Qhk3lsmaetD4NhzNMJun2nJ+hXnWfWe1ZerWA9eUHAKa+dSsge9Ix3T1OkM3DDWnHqrt mU/XeO/XFCrqBQphN8+Ez+sy4kEKuX+16898+NJQjpX64Tt3Azdp183U6Lu+lnsERErG 9SSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [2a00:1098:0:82:1000:25:2eeb:e3e3]) by mx.google.com with ESMTPS id t13si10019593wrn.408.2019.02.18.13.07.27 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:27 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) client-ip=2a00:1098:0:82:1000:25:2eeb:e3e3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id F1D6127F9AB From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 1/6] Revert "kernel/dma: remove unsupported gfp_mask parameter from dma_alloc_from_contiguous()" Date: Mon, 18 Feb 2019 16:07:10 -0500 Message-Id: <20190218210715.1066-2-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit d834c5ab83febf9624ad3b16c3c348aa1e02014c. Commit d834c5ab83fe ("kernel/dma: remove unsupported gfp_mask parameter from dma_alloc_from_contiguous()") attempts to make more clear that the CMA allocator doesn't support all of the standard GFP flags by removing that parameter from cma_alloc(). Unfortunately, this don't make things much more clear about what CMA supports, as exemplified by the ARM DMA layer issue, which simply masks away the GFP_NOIO flag when calling the CMA allocator, letting it assume it is always the hardcoded GFP_KERNEL. The removal of gfp_flags doesn't make any easier to eventually support these flags in the CMA allocator, like the rest of this series attempt to do. Instead, this patch and the next patch restores that parameter. CC: Marek Szyprowski Signed-off-by: Gabriel Krisman Bertazi [Fix new callers] --- arch/arm/mm/dma-mapping.c | 5 ++--- arch/arm64/mm/dma-mapping.c | 2 +- arch/xtensa/kernel/pci-dma.c | 2 +- drivers/iommu/amd_iommu.c | 2 +- drivers/iommu/intel-iommu.c | 3 +-- include/linux/dma-contiguous.h | 4 ++-- kernel/dma/contiguous.c | 7 ++++--- kernel/dma/direct.c | 3 +-- kernel/dma/remap.c | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f1e2922e447c..bc3a62087f52 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -586,7 +586,7 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, struct page *page; void *ptr = NULL; - page = dma_alloc_from_contiguous(dev, count, order, gfp & __GFP_NOWARN); + page = dma_alloc_from_contiguous(dev, count, order, gfp); if (!page) return NULL; @@ -1291,8 +1291,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, unsigned long order = get_order(size); struct page *page; - page = dma_alloc_from_contiguous(dev, count, order, - gfp & __GFP_NOWARN); + page = dma_alloc_from_contiguous(dev, count, order, gfp); if (!page) goto error; diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 78c0a72f822c..660adedaab5d 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -159,7 +159,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size, struct page *page; page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, - get_order(size), gfp & __GFP_NOWARN); + get_order(size), gfp); if (!page) return NULL; diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c index 9171bff76fc4..e15b893caadb 100644 --- a/arch/xtensa/kernel/pci-dma.c +++ b/arch/xtensa/kernel/pci-dma.c @@ -157,7 +157,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, if (gfpflags_allow_blocking(flag)) page = dma_alloc_from_contiguous(dev, count, get_order(size), - flag & __GFP_NOWARN); + flag); if (!page) page = alloc_pages(flag | __GFP_ZERO, get_order(size)); diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 2a7b78bb98b4..23346a7a32fc 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2692,7 +2692,7 @@ static void *alloc_coherent(struct device *dev, size_t size, return NULL; page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, - get_order(size), flag & __GFP_NOWARN); + get_order(size), flag); if (!page) return NULL; } diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 78188bf7e90d..ebaab2d3750f 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -3791,8 +3791,7 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, if (gfpflags_allow_blocking(flags)) { unsigned int count = size >> PAGE_SHIFT; - page = dma_alloc_from_contiguous(dev, count, order, - flags & __GFP_NOWARN); + page = dma_alloc_from_contiguous(dev, count, order, flags); if (page && iommu_no_mapping(dev) && page_to_phys(page) + size > dev->coherent_dma_mask) { dma_release_from_contiguous(dev, page, count); diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h index f247e8aa5e3d..3c5a4cb3eb95 100644 --- a/include/linux/dma-contiguous.h +++ b/include/linux/dma-contiguous.h @@ -112,7 +112,7 @@ static inline int dma_declare_contiguous(struct device *dev, phys_addr_t size, } struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, - unsigned int order, bool no_warn); + unsigned int order, gfp_t gfp_mask); bool dma_release_from_contiguous(struct device *dev, struct page *pages, int count); @@ -145,7 +145,7 @@ int dma_declare_contiguous(struct device *dev, phys_addr_t size, static inline struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, - unsigned int order, bool no_warn) + unsigned int order, gfp_t gfp_mask) { return NULL; } diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b2a87905846d..b1c3109bbd26 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -182,7 +182,7 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * @dev: Pointer to device for which the allocation is performed. * @count: Requested number of pages. * @align: Requested alignment of pages (in PAGE_SIZE order). - * @no_warn: Avoid printing message about failed allocation. + * @gfp_mask: GFP flags to use for this allocation. * * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default @@ -190,12 +190,13 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * function. */ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, - unsigned int align, bool no_warn) + unsigned int align, gfp_t gfp_mask) { if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); + return cma_alloc(dev_get_cma_area(dev), count, align, + gfp_mask & __GFP_NOWARN); } /** diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 355d16acee6d..6c7009dc9cab 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -111,8 +111,7 @@ struct page *__dma_direct_alloc_pages(struct device *dev, size_t size, again: /* CMA can be used only in the context which permits sleeping */ if (gfpflags_allow_blocking(gfp)) { - page = dma_alloc_from_contiguous(dev, count, page_order, - gfp & __GFP_NOWARN); + page = dma_alloc_from_contiguous(dev, count, page_order, gfp); if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) { dma_release_from_contiguous(dev, page, count); page = NULL; diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 7a723194ecbe..862fc8e781c2 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -115,7 +115,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) if (dev_get_cma_area(NULL)) page = dma_alloc_from_contiguous(NULL, nr_pages, - pool_size_order, false); + pool_size_order, gfp); else page = alloc_pages(gfp, pool_size_order); if (!page) From patchwork Mon Feb 18 21:07:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3BE76CB for ; Mon, 18 Feb 2019 21:07:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A22212BC9A for ; Mon, 18 Feb 2019 21:07:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967C42BCBE; Mon, 18 Feb 2019 21:07:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96002BCCD for ; Mon, 18 Feb 2019 21:07:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9E8F8E0005; Mon, 18 Feb 2019 16:07:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9FCF28E0002; Mon, 18 Feb 2019 16:07:32 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 912148E0005; Mon, 18 Feb 2019 16:07:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 3D55E8E0002 for ; Mon, 18 Feb 2019 16:07:32 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id a5so8344299wrq.3 for ; Mon, 18 Feb 2019 13:07:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=bEc+KUL6oe1C5VhMw4UMHOFR8WN9T26UJj4VRTS+sJw=; b=co66ZdMewOASj6OvwWQdSBV7zzTR0QdrrW1SAfrumsn7ty2l19+2M94j9MaZry5yVN 1xEarMyk/Eqod7wxm7Ypu4OK6rWwUOEQ3L4sMrV0sQsdf07DS8nndeRn6xUUW1wgcXij 4eEp9QvV1SRmIkN/Th7semvsy6gop/OfLxy8uBcxgde3vtdezaxYvrflqWMXK0rxkuVp XbkKwbU41hXozKkBwmcauh0sVWVIljVEvUQZ/na/iiU6F6M5TT0nxxn1ZOh+kU2ZT5ty rSOkEhwpfJGwtjI0VKUTR36TlB/JBpQO17+oVciAYx6AYR0nlvLfmDVZl7LKmpRlfQex ROjQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAualPqVg5j2ctCTeSm5da0/Twf71SxqB6OXWpO6Fe+vOHVSxWZIY 6JwxPsKvocDDas/sOFBW/M8tw9Q5saarDdL+sot7vk/PpDPA/p2WN4yIPmgQl6yLp2JXY8mIoGJ IaAyhE3gsjo9vifCwVE97Pv570uJKuXRI0LskSf7lhTRC9asOlH2GYKRQ42HBenQVVA== X-Received: by 2002:adf:a104:: with SMTP id o4mr17607580wro.244.1550524051755; Mon, 18 Feb 2019 13:07:31 -0800 (PST) X-Google-Smtp-Source: AHgI3Iae/GmlaXhCQjRu9X5+FMyN52AoJk8Oq8WHcBbyduuV4/AaxIp5wXMQD7Etj9DZO8RCg7xX X-Received: by 2002:adf:a104:: with SMTP id o4mr17607547wro.244.1550524050674; Mon, 18 Feb 2019 13:07:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524050; cv=none; d=google.com; s=arc-20160816; b=fksBoXXzUfSMqnTtq7ec9fVrs0+7iKLsxlNaHiJ3z9YnWZrgx7bNe1EblLP1NQGoW2 n1Nn050cupVGCXNx5X8ufSEFsYP7VWvsn9TzZtbsa8WU5khN1N6GmMyjzWVTWYv77cLm 1LkvjoAntVpwdKq9VvqWuY/rvdO9GfxY5cU4kyFSZggB2Lz4ECE501F52P2QEDDiEeYB 3QC1vVk1QG/Ym89ykBrwktrwC0IIKUsfA94nLfqcxEnReOTUIhr/tL6Fso9TagRlGIXo D4GBVyGFb33kXBnzoVWCD/zHrZEatSZXFl+9zRr/qGwRCwRmEC9EC3pTAidxOLdaVAcG jPEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=bEc+KUL6oe1C5VhMw4UMHOFR8WN9T26UJj4VRTS+sJw=; b=ZxfeEdCcfV9mj8by2q7E81mJh4y4g9D/URcWe4A0OGr8M+6pzVKMUczwKOOt1ZvvQn jogXolFh1Wz34gyYm14Quv63L7dErLPH+O/XvXJ1BnuEVeRz8htEcqwiWpdbrul3cSq2 lh9tEcO0uxr/qiTMaIGZ6Vf4lUosBl/HiPpBbaHL9MafDIMmh6CT9HNp9Bi5dVeA10h0 D4GppCPt09GCLObG5Ro48YjFQruzPjAQrRvtPWc2JAhVaaxBr4l0jgh7XT5p06d3Nw6p StZ6iwfOSuxBlAc+Y13PAox+Mee753vmhz+zXBs+LzI7zLzR1HqT/l3ycmf1+7DDEPU6 hpyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [2a00:1098:0:82:1000:25:2eeb:e3e3]) by mx.google.com with ESMTPS id c187si268448wma.107.2019.02.18.13.07.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:30 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) client-ip=2a00:1098:0:82:1000:25:2eeb:e3e3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 2C06127FD42 From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 2/6] Revert "mm/cma: remove unsupported gfp_mask parameter from cma_alloc()" Date: Mon, 18 Feb 2019 16:07:11 -0500 Message-Id: <20190218210715.1066-3-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 6518202970c1052148daaef9a8096711775e43a2. Commit 6518202970c1 ("mm/cma: remove unsupported gfp_mask parameter from cma_alloc()") attempts to make more clear that the CMA allocator doesn't support all of the standard GFP flags by removing that parameter from cma_alloc(). Unfortunately, this don't make things much more clear about what CMA supports, as exemplified by the ARM DMA layer issue, which simply masks away the GFP_NOIO flag when calling the CMA allocator, letting it assume it is always the hardcoded GFP_KERNEL. The removal of gfp_flags doesn't make any easier to eventually support these flags in the CMA allocator, like the rest of this series attempt to do. Instead, this patch and the previous one restore that parameter. CC: Marek Szyprowski Signed-off-by: Gabriel Krisman Bertazi --- arch/powerpc/kvm/book3s_hv_builtin.c | 2 +- drivers/s390/char/vmcp.c | 2 +- drivers/staging/android/ion/ion_cma_heap.c | 2 +- include/linux/cma.h | 2 +- kernel/dma/contiguous.c | 3 +-- mm/cma.c | 8 ++++---- mm/cma_debug.c | 2 +- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c index a71e2fc00a4e..925e8f9fc10d 100644 --- a/arch/powerpc/kvm/book3s_hv_builtin.c +++ b/arch/powerpc/kvm/book3s_hv_builtin.c @@ -77,7 +77,7 @@ struct page *kvm_alloc_hpt_cma(unsigned long nr_pages) VM_BUG_ON(order_base_2(nr_pages) < KVM_CMA_CHUNK_ORDER - PAGE_SHIFT); return cma_alloc(kvm_cma, nr_pages, order_base_2(HPT_ALIGN_PAGES), - false); + GFP_KERNEL); } EXPORT_SYMBOL_GPL(kvm_alloc_hpt_cma); diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c index 0fa1b6b1491a..948ce82a7725 100644 --- a/drivers/s390/char/vmcp.c +++ b/drivers/s390/char/vmcp.c @@ -68,7 +68,7 @@ static void vmcp_response_alloc(struct vmcp_session *session) * anymore the system won't work anyway. */ if (order > 2) - page = cma_alloc(vmcp_cma, nr_pages, 0, false); + page = cma_alloc(vmcp_cma, nr_pages, 0, GFP_KERNEL); if (page) { session->response = (char *)page_to_phys(page); session->cma_alloc = 1; diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index 3fafd013d80a..49718c96bf9e 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -39,7 +39,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer, if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - pages = cma_alloc(cma_heap->cma, nr_pages, align, false); + pages = cma_alloc(cma_heap->cma, nr_pages, align, GFP_KERNEL); if (!pages) return -ENOMEM; diff --git a/include/linux/cma.h b/include/linux/cma.h index 190184b5ff32..bf90f0bb42bd 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -33,7 +33,7 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, const char *name, struct cma **res_cma); extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, - bool no_warn); + gfp_t gfp_mask); extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count); extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b1c3109bbd26..54a33337680f 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -195,8 +195,7 @@ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, - gfp_mask & __GFP_NOWARN); + return cma_alloc(dev_get_cma_area(dev), count, align, gfp_mask); } /** diff --git a/mm/cma.c b/mm/cma.c index c7b39dd3b4f6..fdad7ad0d9c4 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -395,13 +395,13 @@ static inline void cma_debug_show_areas(struct cma *cma) { } * @cma: Contiguous memory region for which the allocation is performed. * @count: Requested number of pages. * @align: Requested alignment of pages (in PAGE_SIZE order). - * @no_warn: Avoid printing message about failed allocation + * @gfp_mask: GFP mask to use during compaction * * This function allocates part of contiguous memory on specific * contiguous memory area. */ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, - bool no_warn) + gfp_t gfp_mask) { unsigned long mask, offset; unsigned long pfn = -1; @@ -448,7 +448,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); mutex_lock(&cma_mutex); ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, - GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0)); + gfp_mask); mutex_unlock(&cma_mutex); if (ret == 0) { page = pfn_to_page(pfn); @@ -477,7 +477,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, page_kasan_tag_reset(page + i); } - if (ret && !no_warn) { + if (ret && !(gfp_mask & __GFP_NOWARN)) { pr_err("%s: alloc failed, req-size: %zu pages, ret: %d\n", __func__, count, ret); cma_debug_show_areas(cma); diff --git a/mm/cma_debug.c b/mm/cma_debug.c index ad6723e9d110..f23467291cfb 100644 --- a/mm/cma_debug.c +++ b/mm/cma_debug.c @@ -139,7 +139,7 @@ static int cma_alloc_mem(struct cma *cma, int count) if (!mem) return -ENOMEM; - p = cma_alloc(cma, count, 0, false); + p = cma_alloc(cma, count, 0, GFP_KERNEL); if (!p) { kfree(mem); return -ENOMEM; From patchwork Mon Feb 18 21:07:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69C66139A for ; Mon, 18 Feb 2019 21:07:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 591FC2BC8A for ; Mon, 18 Feb 2019 21:07:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D2F22BCBE; Mon, 18 Feb 2019 21:07:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E16302BC8A for ; Mon, 18 Feb 2019 21:07:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82A888E0006; Mon, 18 Feb 2019 16:07:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7DB228E0002; Mon, 18 Feb 2019 16:07:35 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C7D58E0006; Mon, 18 Feb 2019 16:07:35 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id 2DF038E0002 for ; Mon, 18 Feb 2019 16:07:35 -0500 (EST) Received: by mail-wm1-f69.google.com with SMTP id f202so42840wme.2 for ; Mon, 18 Feb 2019 13:07:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=R6jm3XECd8aWAueqMD0xo2xsLqP/zhyB2FKoKvR4+qI=; b=anen5sq/fU85HgWGXNKZD6y178IBIwG0uU4c0ebc5XAOv2kvg9BKr8ZgS51B7WKmH9 Arn1cw9qQ22jB3PztKe0LHTszQhzCeZ3aEzdrUDFsKW+g81YbLUN/zROWbp0FG0HtFLV ash1HEqCCjLbfD///eGqM7I4qQGGwVLlHNEr71avupTfD3Lif/hoktJ1BTB4sWP87GUU 8WItGL2h+by3JWEfTLEDBaX58nArxV9d5iFhQF36iYLETkYEoOiDp3GGVtDaOhv/19gQ RAI8y9fpYGLZ/FrI1p+GbD673dPzyC/VH3BKqpm144IPM8z6wwOdRPLRmCdJBk3JgnCY RCNw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAuYrA/45XNz7/nDOo1o9ZBelG1tLk+EW7dfSi+1kyNB4QAyV2Gbr eF2z0xwQZF68CwQhBLoJ41bvIOlYeMWLdMoWScpMltS56nZT6PTM7phgocIN6ZE1aIrxsBUodK8 KAWu1IJajqhfXdqu1VG7P9bUfCTGJHCDMxwzt/uSyy0FJXZkO2qHefDALd015THb5AQ== X-Received: by 2002:adf:dc10:: with SMTP id t16mr18701434wri.40.1550524054667; Mon, 18 Feb 2019 13:07:34 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib1SeOOcnWHtPkUGN8ohv62ME9av6d9AmRctPw33TGsg4BlCirrmKP6a+AKSdnlzdw+3DgE X-Received: by 2002:adf:dc10:: with SMTP id t16mr18701405wri.40.1550524053902; Mon, 18 Feb 2019 13:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524053; cv=none; d=google.com; s=arc-20160816; b=bn2wmOW3iUG3/XyuObjVjK/86WW0PTU+nhpr/Jk0Uro9pmUkeUxMQxhy2wnOtmivXD hMaIzdfxOOTOPGU9Mq1BlnR6QXICnbXeDaOm1kDaBjafQKnv0VpomkrzYSOz2zN+E7SA m7YNI4n3rdma1UldHUbkdwGwXlU3hCg4GpLHqCEQBAFkaFcf2f085vy5M8tUNFzibca/ wTsjcKRFkkqaA6yDbFJ8FJl+WeNOW4LCz66HYowHTFpMMY/M7FjxQZVUT9xVCoAEj4JO AblDgjVFZih1i4o086fngfNZrZxtovQBirQgTkQRWhUydVgw8mmiT/OtOjRMGeLDbeOt Xb3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=R6jm3XECd8aWAueqMD0xo2xsLqP/zhyB2FKoKvR4+qI=; b=j76ekZ9PMrcpmHZnDjFytsNo0fyqRIh3cuW+qrMN00awVK0XQoYkgGRvVtu8OFXwG7 PT+7yWrImv7kv8L1EDGmLAXLpr9rwguTTvF4n8mxYoCLbwC75z13VuIgN0m2nL5FS6dJ 18+RGp0fXwczemHgKkJSBw9RZuB6cOfNu1Qnqs9YbZt0r0EIfzWWsqjsnvJdlULm0Nsy fUSeWttzb0JEIQeeJyVCND8r17AbQpjA3+kPA8ZVVyqzzHD5Z0JG5IdPUcfX7Zfi0wTY pAOwQkwJdMwt3t2TFxCqL16JjobnS5LAdCtVdT7xVgtrS9Vc8dDw/XzV5ZAuRTW1/5mO 2fig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [2a00:1098:0:82:1000:25:2eeb:e3e3]) by mx.google.com with ESMTPS id s18si255697wmc.179.2019.02.18.13.07.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:33 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) client-ip=2a00:1098:0:82:1000:25:2eeb:e3e3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 2a00:1098:0:82:1000:25:2eeb:e3e3 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 67BC127F9AB From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 3/6] cma: Warn about callers requesting unsupported flags Date: Mon, 18 Feb 2019 16:07:12 -0500 Message-Id: <20190218210715.1066-4-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The CMA allocator does not support every standard GFP flag. Instead of silently ignoring, we should be noisy about it, to catch wrong code paths early. Signed-off-by: Gabriel Krisman Bertazi --- mm/cma.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index fdad7ad0d9c4..5789e3545faf 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -411,6 +411,10 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, struct page *page = NULL; int ret = -ENOMEM; + /* Be noisy about caller asking for unsupported flags. */ + WARN_ON(unlikely(!(gfp_mask & __GFP_DIRECT_RECLAIM) || + (gfp_mask & (__GFP_ZERO|__GFP_NOFAIL)))); + if (!cma || !cma->count) return NULL; From patchwork Mon Feb 18 21:07:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B355F139A for ; Mon, 18 Feb 2019 21:07:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A26622BC8A for ; Mon, 18 Feb 2019 21:07:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967A62BCBE; Mon, 18 Feb 2019 21:07:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3200B2BC8A for ; Mon, 18 Feb 2019 21:07:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF96E8E0007; Mon, 18 Feb 2019 16:07:38 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BA8C08E0002; Mon, 18 Feb 2019 16:07:38 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABF198E0007; Mon, 18 Feb 2019 16:07:38 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 59A468E0002 for ; Mon, 18 Feb 2019 16:07:38 -0500 (EST) Received: by mail-wr1-f70.google.com with SMTP id f5so8342628wrt.13 for ; Mon, 18 Feb 2019 13:07:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=I00cjU5zXSQrlQOQ0zaNYv7UvzPZwT0wOJkS62bsHzU=; b=pqBYtW8v1ArUoGUZUoNqwaibZ3J6SWbdwdTamy5CLNBCcTlNTC5IbVcTV0Fcmrikc3 L0ZEvV6V/IG0Eay3hdMOtl44u6wwUTsfnR/IcdDNNKyNgOih5WVlj40Te1KYgjhZUY53 nGEzMfsR9bSdobojE4mN/r8TvJ8xYzHhYizXxL5COybOg6dbWMXcIuOgfbDAbk5X7/tQ ewqpGEdyhnAkbe9Bep0UMCwCSCNQmTVbzPnzrdzx/Hrs1cvTcP+BRE1a3SJl5ZSld5nU UPMzOgRgV6wWRZD2SroIUsqHEC4v8dind/aBCAglhjJd+1E/3697P/e/bfyr//FksSx7 GCrw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAuaR4wJd6zB2+9wUx6zsanIQ/Y04mdsHni4qB/LIA9XWXRLd+I5f vGn5d+octjErGB3mJ+CnBac0XO7nTpY/JOpPwKXd8AcGCqPuE/Jzwo6cVhNih0KOaM3s/3mS76I 9BGQ1Wk1+JJF+fnbn1ABQp23BOcp46xPncp5sb2ty9eLlo38FsP3yPAbKQv7b6G/jpg== X-Received: by 2002:a05:600c:2:: with SMTP id g2mr443478wmc.109.1550524057890; Mon, 18 Feb 2019 13:07:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IYA5h7fDWvn5KVmfqCjtEuhBYlX0NZFfQkC9g6ann8iAiHWXsCYa4mWKyBkC9dZ07ky34uI X-Received: by 2002:a05:600c:2:: with SMTP id g2mr443442wmc.109.1550524056880; Mon, 18 Feb 2019 13:07:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524056; cv=none; d=google.com; s=arc-20160816; b=EAbIU76zq6UX+M5gmVUu1WaCFbDt2/3ropBJaczo901XPzogOrj2koIUR628Afao/2 kGArYVSU/F5vP4iKh8msLyULJ/GoExYn2a14MxaEp9EzfLi+8gzyinfZcoNh6Ovf3O/m yQCWXZgX2zxoxSwiTa8qd0y4tQKyHXb1H48OrLbWZfeAUeWrieZ3uCTKxE4+Hsen3ffI 5kfwh+QoYuZemP0dwmJSxDwW43AWRUFpQXAyW1+nHXa0khrrE1egy2Cj1D4LMHGivs6k o6uX+l1ID7aNtFU3CJGSELD/uh5vbX0RrbeUpimMPYzWSlC0htZaE4uvOjrXJ+FybeMf kUag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=I00cjU5zXSQrlQOQ0zaNYv7UvzPZwT0wOJkS62bsHzU=; b=p+GTpNrF0Lz+VpwlVYJ/5W47aCIaocjJiOQ8V3YRsCE6DWp5W4Gq9+UCjrAztj7YsF riyWPTB3e2Uttu86TEW4w9eXABYgmfp//KoY/G0yoK9UpaOkU9JPf9BkYffWZdk3HNFB o4i6Kg1GpoM74E7do0tdQG77Oa8drH1q4EqXzRNfQi08XpzxNKv2+TO7kDsLiF+U3RPk 6KCk7y064CwMUlSUKL2OJf04M4ENlOpwtOvKTjf5Ui/V4iRZ9eYIhK1sja7Rcb9qZkG8 R1t7xA/CP1rPOxngpfd41EDFMHqNHFOeD88GefezYACjq1Uug9AI2IC1fba3EIknJjwW 2Rog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [46.235.227.227]) by mx.google.com with ESMTPS id y22si13866060wrd.342.2019.02.18.13.07.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:36 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) client-ip=46.235.227.227; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 64ABA27FD49 From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 4/6] cma: Add support for GFP_ZERO Date: Mon, 18 Feb 2019 16:07:13 -0500 Message-Id: <20190218210715.1066-5-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Since cma_alloc now has gfp_mask, make it honor GFP_ZERO, to not suprise potential users. Signed-off-by: Gabriel Krisman Bertazi --- mm/cma.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 5789e3545faf..1dff74b1a8c5 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -408,12 +408,13 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, unsigned long start = 0; unsigned long bitmap_maxno, bitmap_no, bitmap_count; size_t i; + void *kaddr; struct page *page = NULL; int ret = -ENOMEM; /* Be noisy about caller asking for unsupported flags. */ WARN_ON(unlikely(!(gfp_mask & __GFP_DIRECT_RECLAIM) || - (gfp_mask & (__GFP_ZERO|__GFP_NOFAIL)))); + (gfp_mask & __GFP_NOFAIL))); if (!cma || !cma->count) return NULL; @@ -477,8 +478,15 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, * those page blocks. */ if (page) { - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { page_kasan_tag_reset(page + i); + + if (gfp_mask & __GFP_ZERO) { + kaddr = kmap_atomic(page + i); + clear_page(kaddr); + kunmap_atomic(kaddr); + } + } } if (ret && !(gfp_mask & __GFP_NOWARN)) { From patchwork Mon Feb 18 21:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F1C0139A for ; Mon, 18 Feb 2019 21:07:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E6702BCBE for ; Mon, 18 Feb 2019 21:07:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22F8A2BCE6; Mon, 18 Feb 2019 21:07:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 981562BCCD for ; Mon, 18 Feb 2019 21:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F0418E0008; Mon, 18 Feb 2019 16:07:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A1F18E0002; Mon, 18 Feb 2019 16:07:42 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 569C88E0008; Mon, 18 Feb 2019 16:07:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 02E8F8E0002 for ; Mon, 18 Feb 2019 16:07:42 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id s5so8094933wrp.17 for ; Mon, 18 Feb 2019 13:07:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WMV4Y+Xxwx0amh79b7ogT26X55X7KS8eKOuS0jAVMLw=; b=msLeedaXi6T3llmVK1F3Gt+CRXpBKGOTNY8XljBxnI52DP3LBgv+W+/JTvfxtLdryw EgjDeB9nq5wlk9+74Dc5nAxnC333s0uKh8gprscZGPVOMc6Iro5OK/oe6Vv+jafm8CzN FvVVgnME9qKYDGxryOXVVSZBQTvFHqAT2PJ4QoxTl+9n5LtyguxWD202by0b/MDHnPhk ZXkB/55GqMBRjshwz6uvigdymKpPNMGT/7QhYtsQ8Qy0kFBcuZos8rcJdAQlUkpiYCLJ c2oDtZuorUFDhN7XPnNnA5MthNCYkeRb5m+9jLvZskXpvgnE2WHEt4GiFmRzK1Z09ga6 3hLA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAubKxyB1AAxTMud7PeyFvTKPHLqnMSnbDUjlxnXqDOGEfUdsLCO6 hlDDDEbT2ooIbgEp8YxuQG/hxRmppvShvGr35hU17cxPrKFo7++weR8yRgs10TDBLWxC9kCyxXi P6j+1Lc/O7paYdyEyN82/EtnX3TY2asBgB41WMChHiTovpW4TpIBu7kuySR3KvL7kqQ== X-Received: by 2002:a1c:cf82:: with SMTP id f124mr458126wmg.95.1550524061526; Mon, 18 Feb 2019 13:07:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IbcJcCenvcMS+ro+i37t+yB4OCXSx7E57ie+fUKpkVgijfBBpMzEEaqp2aCFYBY/MMCFPRv X-Received: by 2002:a1c:cf82:: with SMTP id f124mr458098wmg.95.1550524060639; Mon, 18 Feb 2019 13:07:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524060; cv=none; d=google.com; s=arc-20160816; b=yk6lq7ViewrbeqyxPD/Fg5aucxkjMY6VnjUQQZKgsNNuxbQ0iLBokw6VunyFifAu0d sLq2MOAs7sJMkch+lGlLFcrdOqTVDlQbHhlWrd6wgsJPEn2Bjp6qWVMCcsCJtb9Ewwtk nH9w0hSWh7NsCSuIyUTgOmgfo5tlcO9oVkLN+GfiGsWzLytMZTyLQXSf0681KYIH3DGX OgRSkdtcyIEfJnqYepzM6yzcVYn6WLqs3Oe4ICnlyZ1KMhQKDsU2k/a2NhxtawKSEcPN phNfSgEpUmBosh0lmxaF78XOOLznylAHIBrJNfjoMLGXPscabEmZmNJd7JhBRUcX0Sx1 DqKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=WMV4Y+Xxwx0amh79b7ogT26X55X7KS8eKOuS0jAVMLw=; b=uPyO7omhmOxbkuVqy4Hgf7SnAbFy+cRzqtRZ4VSuwWpb39yXFphNh8B57ftUi6bkyD rNPxnWMOjnIAQ2YqwEvo+Q8a2iECWembLVm9L8oP5tUVTxs23cBfjc1SHoHUq5t5bReA E2Q3K+GmwD72UDcdIUONS7NPRStwZxxrMjjJwA4k/kWmmjtJJpuHCJnaG23plwwNVjN6 Zya1vnXlkzaAAns7CfGV7nnwCMERfSNhcglZ4tTsD1UbSsjBzxJ0SQRa9eY31xpjYlXy dqmVJmuh3nfbrK5E1ts/HBnGQtaE6TDOPJIDCuqxsrBIauWaS/uj2fv7aMz+6mqhZ1ZG tIWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [46.235.227.227]) by mx.google.com with ESMTPS id s15si4528892wrt.209.2019.02.18.13.07.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:40 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) client-ip=46.235.227.227; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 2AB6027F9AB From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 5/6] page_isolation: Propagate temporary pageblock isolation error Date: Mon, 18 Feb 2019 16:07:14 -0500 Message-Id: <20190218210715.1066-6-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP If the page isolation failed because of racing the setup of the pages migrate type, it is very likely that a further attempt will succeed. In this case, instead of -EBUSY, return -EAGAIN, to let callers handle this condition properly. Signed-off-by: Gabriel Krisman Bertazi --- mm/page_isolation.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mm/page_isolation.c b/mm/page_isolation.c index ce323e56b34d..a8169d8ea02d 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -30,10 +30,12 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ /* * We assume the caller intended to SET migrate type to isolate. * If it is already set, then someone else must have raced and - * set it before us. Return -EBUSY + * set it before us. Return -EAGAIN */ - if (is_migrate_isolate_page(page)) + if (is_migrate_isolate_page(page)) { + ret = -EAGAIN; goto out; + } pfn = page_to_pfn(page); arg.start_pfn = pfn; @@ -188,6 +190,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, unsigned long pfn; unsigned long undo_pfn; struct page *page; + int ret = -EBUSY; BUG_ON(!IS_ALIGNED(start_pfn, pageblock_nr_pages)); BUG_ON(!IS_ALIGNED(end_pfn, pageblock_nr_pages)); @@ -196,10 +199,13 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, pfn < end_pfn; pfn += pageblock_nr_pages) { page = __first_valid_page(pfn, pageblock_nr_pages); - if (page && - set_migratetype_isolate(page, migratetype, flags)) { - undo_pfn = pfn; - goto undo; + if (page) { + ret = set_migratetype_isolate(page, migratetype, + flags); + if (ret) { + undo_pfn = pfn; + goto undo; + } } } return 0; @@ -213,7 +219,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, unset_migratetype_isolate(page, migratetype); } - return -EBUSY; + return ret; } /* From patchwork Mon Feb 18 21:07:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10818861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80BCF6CB for ; Mon, 18 Feb 2019 21:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 701422BCBE for ; Mon, 18 Feb 2019 21:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64AD42BCD0; Mon, 18 Feb 2019 21:07:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E09752BCBE for ; Mon, 18 Feb 2019 21:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 989028E0009; Mon, 18 Feb 2019 16:07:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 95EB78E0002; Mon, 18 Feb 2019 16:07:45 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8752C8E0009; Mon, 18 Feb 2019 16:07:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 339D08E0002 for ; Mon, 18 Feb 2019 16:07:45 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id e14so8084896wrt.12 for ; Mon, 18 Feb 2019 13:07:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ot08kmA/prmR/f55o4kl+bDhF7HacSvMwQbe1YSXEVc=; b=AhuGm4Au5yKHDh33MqZGNlE6NNvOCfqX4IXodTQPJHxGf/dVSVpCHheMpr5dp5ptO6 7d9NfUF09lyD/mnlHFPah2vafJOKsa9akhTATecSw+sEyETSXUZ3aSMk3/jAHRk6qXxJ Heo3Yi6YV7gWZqSEeWc45CacuAVmogJldHEm/HsFzPtU1U7bXAVvElzJ+eYK0wfKjdZZ +KQ4FgUIMmnU1CgPyofi4bgxkpx+UtleWRHs2Z3jTRr2AWdEmfOoCoY0pVs8nVFC5MuU EyK4NP4r/bqRaPI+6hDy8cKUGPPZBVALEShPEtardVLxylWXv/Bm0GdJVqvWTyvRpMHp Edxw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com X-Gm-Message-State: AHQUAuaecYpBvJ62yig0TiqCtnpFlh2WI2iBrAsCeMToOeJS9gpHZNfx cO5KiL6yzkQSq6lzsC8rMcsb3RnGx5I+x/THDD3IlIWY+BpnAII41ezNCJI74ZR1Xvoh/t1O0cp 8im4EqqN0xelIb+Cw0+rAMvJ/oczQbiyjCxjtKzRmOGCDajKx6I4nGCfy7N7qWq2vcA== X-Received: by 2002:a5d:4804:: with SMTP id l4mr18657928wrq.177.1550524064723; Mon, 18 Feb 2019 13:07:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IYUmnWcBopepE5FJHeyjydJ86CJSNoe3P4i1eB4iYTSRafY5hxMaKSFMbRL+Umk9fKTPln2 X-Received: by 2002:a5d:4804:: with SMTP id l4mr18657892wrq.177.1550524063604; Mon, 18 Feb 2019 13:07:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524063; cv=none; d=google.com; s=arc-20160816; b=WrX2tuQNf2/zkATyMXMNNYrP8qp2TCfD/cBfnfKA2KP8JdpmwbeDJSkJ4ziKTQoKW7 5j0BWKcuJYhuSQKw9IjcMXmGmkHQVLWeV6ZxG7SmTlHNgUdnMTOs+hO1+3IidaVlPVWk f/OUQt8Q/nWxw30D1fFsnXOgKF208cRzU8Mvo74/zF03crcRC4HhBGdJYcYBO3xqGzuW QpDX99FsNqh2I2F+nhAVdtYJHQ7l8KBJwyR5hC8HDZp0qWB/ZF+/GRRmroXhcLb6gRQR 4ce2E19+tsbT7GxwQCAM4St7MUVLJHe7wNgeZAWxFWueqsla7ExJ0OjEC89kqm+JbJXp AdrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ot08kmA/prmR/f55o4kl+bDhF7HacSvMwQbe1YSXEVc=; b=Bowcyg+8ry+8hxSnhhSLK6t9KK/nL/iM+srDKq1GkndCxNhHy1mEmlX0MMqak70b9c KSI3IvPRb6ZTeEFp1rSeGvqmpga/mY+W2TIx8aHnCMm4QwjG7TAcfDKtPaa9ARFK8onr bReyVlQg/MhCoH16iEcgR8QlyTnupj8K0sNfUz5MRK8sKq+MeGNdmkIGmiRlD9GZW4jz LWNF6mtXsxuBll4qTHbO4ETtewCj83mUywzUAYxBaNS3e4Vrh++osvjXRPBMbrKi6J3S JT9xQnX/oV+4ZGm/Z6QbqFWEjpo5r9qhv7BU8Mqw70Nu3HzI6k03JqqEbhaYKwQ3+ui2 FU0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [46.235.227.227]) by mx.google.com with ESMTPS id y9si10172692wro.150.2019.02.18.13.07.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 13:07:43 -0800 (PST) Received-SPF: pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) client-ip=46.235.227.227; Authentication-Results: mx.google.com; spf=pass (google.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 221F827FD47 From: Gabriel Krisman Bertazi To: linux-mm@kvack.org Cc: labbott@redhat.com, kernel@collabora.com, gael.portay@collabora.com, mike.kravetz@oracle.com, m.szyprowski@samsung.com, Gabriel Krisman Bertazi Subject: [PATCH 6/6] cma: Isolate pageblocks speculatively during allocation Date: Mon, 18 Feb 2019 16:07:15 -0500 Message-Id: <20190218210715.1066-7-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218210715.1066-1-krisman@collabora.com> References: <20190218210715.1066-1-krisman@collabora.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Holding the mutex when calling alloc_contig_range() is not essential because of the bitmap reservation plus the implicit synchronization mechanism inside start_isolate_page_range(), which prevents allocations on the same pageblock. It is still beneficial to perform some kind of serialization on this path, though, to allow allocations on the same pageblock, if possible, instead of immediately jumping to another allocatable region. Therefore, this patch, instead of serializing every CMA allocation, speculatively try to do the allocation without acquiring the mutex. If we race with another thread allocating on the same pageblock, we can retry on the same region, after waiting for the other colliding allocations to finish. The synchronization of aborted tasks is still done globaly for the CMA allocator. Ideally, the aborted allocation would wait only for the migration of the colliding pageblock, but there is no easy way to track each pageblock isolation in a non-racy way without adding more code overhead. Thus, I believe the mutex mechanism to be an acceptable compromise, if it is not violating the mutex semantics too much. Finally, some code paths like the writeback case, should not blindly sleep waiting for the mutex, because of the possibility of deadlocking if it is a dependency of another allocation thread that holds the mutex. This exact scenario was observed by Gael Portay, with a GPU thread that allocs CMA triggering a writeback, and a USB device in the ARM device that tries to satisfy the writeback with a NOIO CMA allocation [1]. For that reason, we restrict writeback threads from waiting on the pageblock, and instead, we let them move on to a readily available contiguous memory region, effectively preventing the issue reported in [1]. [1] https://groups.google.com/a/lists.one-eyed-alien.net/forum/#!topic/usb-storage/BXpAsg-G1us Signed-off-by: Gabriel Krisman Bertazi --- mm/cma.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 1dff74b1a8c5..ace978623b8d 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -411,6 +411,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, void *kaddr; struct page *page = NULL; int ret = -ENOMEM; + bool has_lock = false; /* Be noisy about caller asking for unsupported flags. */ WARN_ON(unlikely(!(gfp_mask & __GFP_DIRECT_RECLAIM) || @@ -451,17 +452,39 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, mutex_unlock(&cma->lock); pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); - mutex_lock(&cma_mutex); + + /* Mutual exclusion inside alloc_contig_range() is not + * strictly necessary, but it makes the allocation a + * little more likely to succeed, because it serializes + * simultaneous allocations on the same pageblock. We + * cannot sleep on all paths, though, so try to do the + * allocation speculatively, if we identify another + * thread using the same pageblock, fallback to the + * serial path mutex, if possible, or try another + * pageblock, otherwise. + */ + has_lock = mutex_trylock(&cma_mutex); +retry: ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, gfp_mask); - mutex_unlock(&cma_mutex); + + if (ret == -EAGAIN && (gfp_mask & __GFP_IO)) { + if (!has_lock) { + mutex_lock(&cma_mutex); + has_lock = true; + } + goto retry; + } + if (has_lock) + mutex_unlock(&cma_mutex); + if (ret == 0) { page = pfn_to_page(pfn); break; } cma_clear_bitmap(cma, pfn, count); - if (ret != -EBUSY) + if (ret != -EBUSY && ret != -EAGAIN) break; pr_debug("%s(): memory range at %p is busy, retrying\n",