{"id":2219718,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2219718/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-arc/patch/20260403170432.v4.7.If839f6dde98979fce177f70c6c74689a1904ee76@changeid/","project":{"id":48,"url":"http://patchwork.ozlabs.org/api/1.1/projects/48/?format=json","name":"Linux ARC development","link_name":"linux-arc","list_id":"linux-snps-arc.lists.infradead.org","list_email":"linux-snps-arc@lists.infradead.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260403170432.v4.7.If839f6dde98979fce177f70c6c74689a1904ee76@changeid>","date":"2026-04-04T00:05:01","name":"[v4,7/9] driver core: Replace dev->dma_coherent with dev_dma_coherent()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"623856d9201265271eeb37fc6fbfd4662000a1ef","submitter":{"id":9763,"url":"http://patchwork.ozlabs.org/api/1.1/people/9763/?format=json","name":"Douglas Anderson","email":"dianders@chromium.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-arc/patch/20260403170432.v4.7.If839f6dde98979fce177f70c6c74689a1904ee76@changeid/mbox/","series":[{"id":498686,"url":"http://patchwork.ozlabs.org/api/1.1/series/498686/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-arc/list/?series=498686","date":"2026-04-04T00:04:54","name":"driver core: Fix some race conditions","version":4,"mbox":"http://patchwork.ozlabs.org/series/498686/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219718/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219718/checks/","tags":{},"headers":{"Return-Path":"\n <linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=MHR+yrgV;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256\n header.s=google header.b=mMr8UqtB;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fnbWh4gQcz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 04 Apr 2026 11:07:44 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8oYB-00000002khp-22wx;\n\tSat, 04 Apr 2026 00:07:43 +0000","from mail-dl1-x122a.google.com ([2607:f8b0:4864:20::122a])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8oY8-00000002kfk-2DKg\n\tfor linux-snps-arc@lists.infradead.org;\n\tSat, 04 Apr 2026 00:07:42 +0000","by mail-dl1-x122a.google.com with SMTP id\n a92af1059eb24-1273349c56bso2910984c88.0\n        for <linux-snps-arc@lists.infradead.org>;\n Fri, 03 Apr 2026 17:07:40 -0700 (PDT)","from dianders.sjc.corp.google.com\n ([2a00:79e0:2e7c:8:a8b6:55b2:3eb6:2c0e])\n        by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2ca79e1d93bsm6520716eec.12.2026.04.03.17.07.36\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Fri, 03 Apr 2026 17:07:38 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=U0oczSXvBKnwYQuSLlivQWYv8BGWYXvBgExoiQO40Jg=; b=MHR+yrgV0GmIjP\n\tcsrEpCpNI3jyJ8lr1XkLkygGygnko20VHvM9BHj239CnzFjS/K9MJsb6uaBurtozj+W2vk1Ae0p/N\n\txZD9uCMBxh54VqecLJQqkazq/LWtMSUnR2MtaE9RVteotLJKhG88kgCCnbNb9apwQTmyWJTBKRRyz\n\tbJ9+MljYMnjw3JtrnPGF70zmbtFh6nIvVumLB/GlCCbN5w+9ItAfCqlkaLq2UJX+hGZa1/mLscjoi\n\tlD1EXDcSmiwgrADBmzYBS45qbGek0R8ZJaZF11uesUn0b/ForIjsAhcZt+53KAyHZC8c1KiQp+OxJ\n\tFRFFE7LJ29QM7ER0HSug==;","v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=chromium.org; s=google; t=1775261260; x=1775866060;\n darn=lists.infradead.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=pcmabhgoUijh3Cpj42DFAN00fMUT4ppReLQYE5Q7FAg=;\n        b=mMr8UqtBJw+oDcNrqrpG1h9qrnk7OxlpebRKZyNDfLN0PfqXjoi3npm5uLIMiHwYfB\n         m19V1qZHA7kvYxVxvAmx6MLloc+7NA4p8+tGKUge8v/3Wwen27ZiIk4q0h3lYGqusEyd\n         iIKOgiFXIrGqqvGVkqjgjk+GYD/5j4Q5gFyHQ="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775261260; x=1775866060;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=pcmabhgoUijh3Cpj42DFAN00fMUT4ppReLQYE5Q7FAg=;\n        b=ngNXktT46UlNABZnFpLNoLVK9MznRMKqPPlOqwsYjoZVg2bT1iFHd0jeFIjpp1jM+u\n         tAPDZknLErYvO0KYUDjBLCk9egfe7MsDE+xkvuuItWnbw25aTUl4NKg2b751UqDEFC72\n         R2ZOwkFJaCGgs6nAEphEEsGAGsZAGnDx7yeJUQo+b+19YB33I1j9gsx81nUR1OAfQSTJ\n         xrwFZpV6nZPv2aqtjIzunTfP/R0jUoDH0TQQzGsTGGZVyXWrml9O17ahq7MwBHQX6cDq\n         NvXon2gWHihO5L9sRJ9kz+Dlw7d3hVLDL7z3Lv/coUEkzIkwJExNyg/DJ5Xva/Xd98b8\n         EjTw==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXOwHZF6enRe37ay4Y1es1SUEtSgNKicTnTGNkH2f4srlB+TXPGJupBAYAwW41/k98vmdiVzOFMPnu6AflV5w==@lists.infradead.org","X-Gm-Message-State":"AOJu0YzU4CwBK8TxKRgn7m+rrl27X/eYixpXq3oVkVzXSkvGgZONtVbt\n\tMJhfIDbSDHeEMeMBFPDcD5gOKnvbtncPmuBZsKXZ7vAwBtYROzLZWNebDezkE7s50Q==","X-Gm-Gg":"ATEYQzxNeWUs95xf5Mb5G70UWcTuIP15Kdcn82+si2DbIy0TEoZw6eMtwxcGK4g4Fcf\n\ti4PWGeX9tFCcVg1XIh3iW3DdQL3Jowuv/i+V9rW7xMiFZH4SCS2tKRx/IJzux9YJcgXTgzxr76t\n\tQLSwqUBLFDib0JGo9rsdUnmZb4QjoLNSBu+pYKDCjXfQ4LvdFP30Zz1q1ooR9pnWmLUzqqe1lqy\n\teqYmBGLcg9zz5M94RfH0y6KwM6v0zroWqN/KNRg4F/dwPNXUhWp5ayzJTE9vbTRDh1jYqIzfg8V\n\t9SLgXpLySwkjiOA2isPtNSlDrPGvs2m+Ce7lnESkFlKk2H1fyqr1H8oTqjaOmPGggCuKUbs+kJ3\n\to88Mu9/dEy4buK8dR97kRfng/i7+SMWBIdMsGwUyk0xiADy2yHEPZkvTE6+aHER3rqEI5AIiJYp\n\tyQA6Z+gG1Qq9qkjSYambjkfKoeVQRVLPh7q9YEPWcy649ZeG0e8Sf5bdNkXH93ZTjZ8eIe6+20M\n\tfdoV7NMVYU=","X-Received":"by 2002:a05:7022:ec17:b0:123:3488:899f with SMTP id\n a92af1059eb24-12bfb776e08mr1990633c88.32.1775261259525;\n        Fri, 03 Apr 2026 17:07:39 -0700 (PDT)","From":"Douglas Anderson <dianders@chromium.org>","To":"Greg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\t\"Rafael J . Wysocki\" <rafael@kernel.org>,\n\tDanilo Krummrich <dakr@kernel.org>,\n\tAlan Stern <stern@rowland.harvard.edu>","Cc":"Saravana Kannan <saravanak@kernel.org>,\n\tChristoph Hellwig <hch@lst.de>,\n\tEric Dumazet <edumazet@google.com>,\n\tJohan Hovold <johan@kernel.org>,\n\tLeon Romanovsky <leon@kernel.org>,\n\tAlexander Lobakin <aleksander.lobakin@intel.com>,\n\tAlexey Kardashevskiy <aik@ozlabs.ru>,\n\tRobin Murphy <robin.murphy@arm.com>,\n\tDouglas Anderson <dianders@chromium.org>,\n\tFrank.Li@kernel.org,\n\talex@ghiti.fr,\n\tandre.przywara@arm.com,\n\tandrew@lunn.ch,\n\taou@eecs.berkeley.edu,\n\tcatalin.marinas@arm.com,\n\tdmaengine@vger.kernel.org,\n\tdriver-core@lists.linux.dev,\n\tgregory.clement@bootlin.com,\n\tiommu@lists.linux.dev,\n\tjgg@ziepe.ca,\n\tkees@kernel.org,\n\tlinux-arm-kernel@lists.infradead.org,\n\tlinux-kernel@vger.kernel.org,\n\tlinux-mips@vger.kernel.org,\n\tlinux-riscv@lists.infradead.org,\n\tlinux-snps-arc@lists.infradead.org,\n\tlinux@armlinux.org.uk,\n\tm.szyprowski@samsung.com,\n\tpalmer@dabbelt.com,\n\tpeter.ujfalusi@gmail.com,\n\tpjw@kernel.org,\n\tsebastian.hesselbarth@gmail.com,\n\ttsbogend@alpha.franken.de,\n\tvgupta@kernel.org,\n\tvkoul@kernel.org,\n\twill@kernel.org,\n\twilly@infradead.org","Subject":"[PATCH v4 7/9] driver core: Replace dev->dma_coherent with\n dev_dma_coherent()","Date":"Fri,  3 Apr 2026 17:05:01 -0700","Message-ID":"\n <20260403170432.v4.7.If839f6dde98979fce177f70c6c74689a1904ee76@changeid>","X-Mailer":"git-send-email 2.53.0.1213.gd9a14994de-goog","In-Reply-To":"<20260404000644.522677-1-dianders@chromium.org>","References":"<20260404000644.522677-1-dianders@chromium.org>","MIME-Version":"1.0","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260403_170740_610332_7C135383 ","X-CRM114-Status":"GOOD (  24.84  )","X-Spam-Score":"-2.6 (--)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  In C,\n bitfields are not necessarily safe to modify from multiple\n    threads without locking. Switch \"dma_coherent\" over to the \"flags\" field\n   so modifications are safe. Cc: Christoph Hellwig <hch@lst.de>\n Signed-off-by:\n    Douglas Anderson <dianders@chromium.org> --- Not fixing any known bugs;\n problem\n    is theoretical and found by code inspection. Change is done somewhat m\n [...]    \n Content analysis details:   (-2.6 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/, no\n                             trust\n                             [2607:f8b0:4864:20:0:0:0:122a listed in]\n                             [list.dnswl.org]\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]\n -0.5 DKIMWL_WL_HIGH         DKIMwl.org - High trust sender","X-BeenThere":"linux-snps-arc@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux on Synopsys ARC Processors <linux-snps-arc.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-snps-arc/>","List-Post":"<mailto:linux-snps-arc@lists.infradead.org>","List-Help":"<mailto:linux-snps-arc-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-snps-arc\" <linux-snps-arc-bounces@lists.infradead.org>","Errors-To":"\n linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"In C, bitfields are not necessarily safe to modify from multiple\nthreads without locking. Switch \"dma_coherent\" over to the \"flags\"\nfield so modifications are safe.\n\nCc: Christoph Hellwig <hch@lst.de>\nSigned-off-by: Douglas Anderson <dianders@chromium.org>\n---\nNot fixing any known bugs; problem is theoretical and found by code\ninspection. Change is done somewhat manually and only lightly tested\n(mostly compile-time tested).\n\nNOTE: even though previously we only took up a bit if\nCONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE, CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU,\nor CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL, in this change I reserve the\nbit unconditionally.  While we could get the \"dynamic\" behavior by\nchanging the flags definition to be an \"enum\", it doesn't seem worth\nit at this point.\n\nChanges in v4:\n- Use accessor functions for flags\n\nChanges in v3:\n- New\n\n arch/arc/mm/dma.c                 |  4 ++--\n arch/arm/mach-highbank/highbank.c |  2 +-\n arch/arm/mach-mvebu/coherency.c   |  2 +-\n arch/arm/mm/dma-mapping-nommu.c   |  4 ++--\n arch/arm/mm/dma-mapping.c         | 28 ++++++++++++++--------------\n arch/arm64/mm/dma-mapping.c       |  2 +-\n arch/mips/mm/dma-noncoherent.c    |  2 +-\n arch/riscv/mm/dma-noncoherent.c   |  2 +-\n drivers/base/core.c               |  2 +-\n drivers/dma/ti/k3-udma-glue.c     |  6 +++---\n drivers/dma/ti/k3-udma.c          |  6 +++---\n include/linux/device.h            | 11 ++++-------\n include/linux/dma-map-ops.h       |  2 +-\n 13 files changed, 35 insertions(+), 38 deletions(-)","diff":"diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c\nindex 6b85e94f3275..9b9adb02b4c5 100644\n--- a/arch/arc/mm/dma.c\n+++ b/arch/arc/mm/dma.c\n@@ -98,8 +98,8 @@ void arch_setup_dma_ops(struct device *dev, bool coherent)\n \t * DMA buffers.\n \t */\n \tif (is_isa_arcv2() && ioc_enable && coherent)\n-\t\tdev->dma_coherent = true;\n+\t\tdev_set_dma_coherent(dev);\n \n \tdev_info(dev, \"use %scoherent DMA ops\\n\",\n-\t\t dev->dma_coherent ? \"\" : \"non\");\n+\t\t dev_dma_coherent(dev) ? \"\" : \"non\");\n }\ndiff --git a/arch/arm/mach-highbank/highbank.c b/arch/arm/mach-highbank/highbank.c\nindex 47335c7dadf8..8b7d0929dac4 100644\n--- a/arch/arm/mach-highbank/highbank.c\n+++ b/arch/arm/mach-highbank/highbank.c\n@@ -98,7 +98,7 @@ static int highbank_platform_notifier(struct notifier_block *nb,\n \tif (of_property_read_bool(dev->of_node, \"dma-coherent\")) {\n \t\tval = readl(sregs_base + reg);\n \t\twritel(val | 0xff01, sregs_base + reg);\n-\t\tdev->dma_coherent = true;\n+\t\tdev_set_dma_coherent(dev);\n \t}\n \n \treturn NOTIFY_OK;\ndiff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c\nindex fa2c1e1aeb96..7234d487ff39 100644\n--- a/arch/arm/mach-mvebu/coherency.c\n+++ b/arch/arm/mach-mvebu/coherency.c\n@@ -95,7 +95,7 @@ static int mvebu_hwcc_notifier(struct notifier_block *nb,\n \n \tif (event != BUS_NOTIFY_ADD_DEVICE)\n \t\treturn NOTIFY_DONE;\n-\tdev->dma_coherent = true;\n+\tdev_set_dma_coherent(dev);\n \n \treturn NOTIFY_OK;\n }\ndiff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c\nindex fecac107fd0d..c6a70686507b 100644\n--- a/arch/arm/mm/dma-mapping-nommu.c\n+++ b/arch/arm/mm/dma-mapping-nommu.c\n@@ -42,11 +42,11 @@ void arch_setup_dma_ops(struct device *dev, bool coherent)\n \t\t * enough to check if MPU is in use or not since in absence of\n \t\t * MPU system memory map is used.\n \t\t */\n-\t\tdev->dma_coherent = cacheid ? coherent : true;\n+\t\tdev_assign_dma_coherent(dev, cacheid ? coherent : true);\n \t} else {\n \t\t/*\n \t\t * Assume coherent DMA in case MMU/MPU has not been set up.\n \t\t */\n-\t\tdev->dma_coherent = (get_cr() & CR_M) ? coherent : true;\n+\t\tdev_assign_dma_coherent(dev, (get_cr() & CR_M) ? coherent : true);\n \t}\n }\ndiff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c\nindex f304037d1c34..f9bc53b60f99 100644\n--- a/arch/arm/mm/dma-mapping.c\n+++ b/arch/arm/mm/dma-mapping.c\n@@ -1076,7 +1076,7 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,\n \tpgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);\n \tstruct page **pages;\n \tvoid *addr = NULL;\n-\tint coherent_flag = dev->dma_coherent ? COHERENT : NORMAL;\n+\tint coherent_flag = dev_dma_coherent(dev) ? COHERENT : NORMAL;\n \n \t*handle = DMA_MAPPING_ERROR;\n \tsize = PAGE_ALIGN(size);\n@@ -1124,7 +1124,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,\n \tif (vma->vm_pgoff >= nr_pages)\n \t\treturn -ENXIO;\n \n-\tif (!dev->dma_coherent)\n+\tif (!dev_dma_coherent(dev))\n \t\tvma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot);\n \n \terr = vm_map_pages(vma, pages, nr_pages);\n@@ -1141,7 +1141,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,\n static void arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,\n \tdma_addr_t handle, unsigned long attrs)\n {\n-\tint coherent_flag = dev->dma_coherent ? COHERENT : NORMAL;\n+\tint coherent_flag = dev_dma_coherent(dev) ? COHERENT : NORMAL;\n \tstruct page **pages;\n \tsize = PAGE_ALIGN(size);\n \n@@ -1202,7 +1202,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,\n \t\tphys_addr_t phys = page_to_phys(sg_page(s));\n \t\tunsigned int len = PAGE_ALIGN(s->offset + s->length);\n \n-\t\tif (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))\n+\t\tif (!dev_dma_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))\n \t\t\tarch_sync_dma_for_device(sg_phys(s), s->length, dir);\n \n \t\tprot = __dma_info_to_prot(dir, attrs);\n@@ -1304,7 +1304,7 @@ static void arm_iommu_unmap_sg(struct device *dev,\n \t\tif (sg_dma_len(s))\n \t\t\t__iommu_remove_mapping(dev, sg_dma_address(s),\n \t\t\t\t\t       sg_dma_len(s));\n-\t\tif (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))\n+\t\tif (!dev_dma_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))\n \t\t\tarch_sync_dma_for_cpu(sg_phys(s), s->length, dir);\n \t}\n }\n@@ -1323,7 +1323,7 @@ static void arm_iommu_sync_sg_for_cpu(struct device *dev,\n \tstruct scatterlist *s;\n \tint i;\n \n-\tif (dev->dma_coherent)\n+\tif (dev_dma_coherent(dev))\n \t\treturn;\n \n \tfor_each_sg(sg, s, nents, i)\n@@ -1345,7 +1345,7 @@ static void arm_iommu_sync_sg_for_device(struct device *dev,\n \tstruct scatterlist *s;\n \tint i;\n \n-\tif (dev->dma_coherent)\n+\tif (dev_dma_coherent(dev))\n \t\treturn;\n \n \tfor_each_sg(sg, s, nents, i)\n@@ -1371,7 +1371,7 @@ static dma_addr_t arm_iommu_map_phys(struct device *dev, phys_addr_t phys,\n \tdma_addr_t dma_addr;\n \tint ret, prot;\n \n-\tif (!dev->dma_coherent &&\n+\tif (!dev_dma_coherent(dev) &&\n \t    !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO)))\n \t\tarch_sync_dma_for_device(phys, size, dir);\n \n@@ -1412,7 +1412,7 @@ static void arm_iommu_unmap_phys(struct device *dev, dma_addr_t handle,\n \tif (!iova)\n \t\treturn;\n \n-\tif (!dev->dma_coherent &&\n+\tif (!dev_dma_coherent(dev) &&\n \t    !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) {\n \t\tphys_addr_t phys = iommu_iova_to_phys(mapping->domain, iova);\n \n@@ -1431,7 +1431,7 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev,\n \tunsigned int offset = handle & ~PAGE_MASK;\n \tphys_addr_t phys;\n \n-\tif (dev->dma_coherent || !iova)\n+\tif (dev_dma_coherent(dev) || !iova)\n \t\treturn;\n \n \tphys = iommu_iova_to_phys(mapping->domain, iova);\n@@ -1446,7 +1446,7 @@ static void arm_iommu_sync_single_for_device(struct device *dev,\n \tunsigned int offset = handle & ~PAGE_MASK;\n \tphys_addr_t phys;\n \n-\tif (dev->dma_coherent || !iova)\n+\tif (dev_dma_coherent(dev) || !iova)\n \t\treturn;\n \n \tphys = iommu_iova_to_phys(mapping->domain, iova);\n@@ -1701,13 +1701,13 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { }\n void arch_setup_dma_ops(struct device *dev, bool coherent)\n {\n \t/*\n-\t * Due to legacy code that sets the ->dma_coherent flag from a bus\n-\t * notifier we can't just assign coherent to the ->dma_coherent flag\n+\t * Due to legacy code that sets the dma_coherent flag from a bus\n+\t * notifier we can't just assign coherent to the dma_coherent flag\n \t * here, but instead have to make sure we only set but never clear it\n \t * for now.\n \t */\n \tif (coherent)\n-\t\tdev->dma_coherent = true;\n+\t\tdev_set_dma_coherent(dev);\n \n \t/*\n \t * Don't override the dma_ops if they have already been set. Ideally\ndiff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c\nindex b2b5792b2caa..dc1fce939451 100644\n--- a/arch/arm64/mm/dma-mapping.c\n+++ b/arch/arm64/mm/dma-mapping.c\n@@ -48,7 +48,7 @@ void arch_setup_dma_ops(struct device *dev, bool coherent)\n \t\t   dev_driver_string(dev), dev_name(dev),\n \t\t   ARCH_DMA_MINALIGN, cls);\n \n-\tdev->dma_coherent = coherent;\n+\tdev_assign_dma_coherent(dev, coherent);\n \n \txen_setup_dma_ops(dev);\n }\ndiff --git a/arch/mips/mm/dma-noncoherent.c b/arch/mips/mm/dma-noncoherent.c\nindex ab4f2a75a7d0..30ef3e247eb7 100644\n--- a/arch/mips/mm/dma-noncoherent.c\n+++ b/arch/mips/mm/dma-noncoherent.c\n@@ -139,6 +139,6 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,\n #ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS\n void arch_setup_dma_ops(struct device *dev, bool coherent)\n {\n-\tdev->dma_coherent = coherent;\n+\tdev_assign_dma_coherent(dev, coherent);\n }\n #endif\ndiff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c\nindex cb89d7e0ba88..a1ec2d71d1c9 100644\n--- a/arch/riscv/mm/dma-noncoherent.c\n+++ b/arch/riscv/mm/dma-noncoherent.c\n@@ -140,7 +140,7 @@ void arch_setup_dma_ops(struct device *dev, bool coherent)\n \t\t   \"%s %s: device non-coherent but no non-coherent operations supported\",\n \t\t   dev_driver_string(dev), dev_name(dev));\n \n-\tdev->dma_coherent = coherent;\n+\tdev_assign_dma_coherent(dev, coherent);\n }\n \n void riscv_noncoherent_supported(void)\ndiff --git a/drivers/base/core.c b/drivers/base/core.c\nindex 0986051a6f14..531f02a5469a 100644\n--- a/drivers/base/core.c\n+++ b/drivers/base/core.c\n@@ -3173,7 +3173,7 @@ void device_initialize(struct device *dev)\n #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \\\n     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \\\n     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)\n-\tdev->dma_coherent = dma_default_coherent;\n+\tdev_assign_dma_coherent(dev, dma_default_coherent);\n #endif\n \tswiotlb_dev_init(dev);\n }\ndiff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c\nindex f87d244cc2d6..686dc140293e 100644\n--- a/drivers/dma/ti/k3-udma-glue.c\n+++ b/drivers/dma/ti/k3-udma-glue.c\n@@ -312,7 +312,7 @@ k3_udma_glue_request_tx_chn_common(struct device *dev,\n \n \tif (xudma_is_pktdma(tx_chn->common.udmax)) {\n \t\t/* prepare the channel device as coherent */\n-\t\ttx_chn->common.chan_dev.dma_coherent = true;\n+\t\tdev_set_dma_coherent(&tx_chn->common.chan_dev);\n \t\tdma_coerce_mask_and_coherent(&tx_chn->common.chan_dev,\n \t\t\t\t\t     DMA_BIT_MASK(48));\n \t}\n@@ -1003,7 +1003,7 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name,\n \n \tif (xudma_is_pktdma(rx_chn->common.udmax)) {\n \t\t/* prepare the channel device as coherent */\n-\t\trx_chn->common.chan_dev.dma_coherent = true;\n+\t\tdev_set_dma_coherent(&rx_chn->common.chan_dev);\n \t\tdma_coerce_mask_and_coherent(&rx_chn->common.chan_dev,\n \t\t\t\t\t     DMA_BIT_MASK(48));\n \t}\n@@ -1104,7 +1104,7 @@ k3_udma_glue_request_remote_rx_chn_common(struct k3_udma_glue_rx_channel *rx_chn\n \n \tif (xudma_is_pktdma(rx_chn->common.udmax)) {\n \t\t/* prepare the channel device as coherent */\n-\t\trx_chn->common.chan_dev.dma_coherent = true;\n+\t\tdev_set_dma_coherent(&rx_chn->common.chan_dev);\n \t\tdma_coerce_mask_and_coherent(&rx_chn->common.chan_dev,\n \t\t\t\t\t     DMA_BIT_MASK(48));\n \t\trx_chn->single_fdq = false;\ndiff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c\nindex c964ebfcf3b6..1cf158eb7bdb 100644\n--- a/drivers/dma/ti/k3-udma.c\n+++ b/drivers/dma/ti/k3-udma.c\n@@ -428,18 +428,18 @@ static void k3_configure_chan_coherency(struct dma_chan *chan, u32 asel)\n \t\t/* No special handling for the channel */\n \t\tchan->dev->chan_dma_dev = false;\n \n-\t\tchan_dev->dma_coherent = false;\n+\t\tdev_clear_dma_coherent(chan_dev);\n \t\tchan_dev->dma_parms = NULL;\n \t} else if (asel == 14 || asel == 15) {\n \t\tchan->dev->chan_dma_dev = true;\n \n-\t\tchan_dev->dma_coherent = true;\n+\t\tdev_set_dma_coherent(chan_dev);\n \t\tdma_coerce_mask_and_coherent(chan_dev, DMA_BIT_MASK(48));\n \t\tchan_dev->dma_parms = chan_dev->parent->dma_parms;\n \t} else {\n \t\tdev_warn(chan->device->dev, \"Invalid ASEL value: %u\\n\", asel);\n \n-\t\tchan_dev->dma_coherent = false;\n+\t\tdev_clear_dma_coherent(chan_dev);\n \t\tchan_dev->dma_parms = NULL;\n \t}\n }\ndiff --git a/include/linux/device.h b/include/linux/device.h\nindex a1d59ff9702c..fca986cef2ed 100644\n--- a/include/linux/device.h\n+++ b/include/linux/device.h\n@@ -481,6 +481,8 @@ struct device_physical_location {\n  * @DEV_FLAG_STATE_SYNCED: The hardware state of this device has been synced to\n  *\t\tmatch the software state of this device by calling the\n  *\t\tdriver/bus sync_state() callback.\n+ * @DEV_FLAG_DMA_COHERENT: This particular device is dma coherent, even if the\n+ *\t\tarchitecture supports non-coherent devices.\n  */\n enum struct_device_flags {\n \tDEV_FLAG_READY_TO_PROBE = 0,\n@@ -489,6 +491,7 @@ enum struct_device_flags {\n \tDEV_FLAG_DMA_SKIP_SYNC = 3,\n \tDEV_FLAG_DMA_OPS_BYPASS = 4,\n \tDEV_FLAG_STATE_SYNCED = 5,\n+\tDEV_FLAG_DMA_COHERENT = 6,\n \n \tDEV_FLAG_COUNT\n };\n@@ -572,8 +575,6 @@ enum struct_device_flags {\n  * @offline:\tSet after successful invocation of bus type's .offline().\n  * @of_node_reused: Set if the device-tree node is shared with an ancestor\n  *              device.\n- * @dma_coherent: this particular device is dma coherent, even if the\n- *\t\tarchitecture supports non-coherent devices.\n  * @flags:\tDEV_FLAG_XXX flags. Use atomic bitfield operations to modify.\n  *\n  * At the lowest level, every device in a Linux system is represented by an\n@@ -681,11 +682,6 @@ struct device {\n \tbool\t\t\toffline_disabled:1;\n \tbool\t\t\toffline:1;\n \tbool\t\t\tof_node_reused:1;\n-#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \\\n-    defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \\\n-    defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)\n-\tbool\t\t\tdma_coherent:1;\n-#endif\n \n \tDECLARE_BITMAP(flags, DEV_FLAG_COUNT);\n };\n@@ -718,6 +714,7 @@ __create_dev_flag_accessors(dma_iommu, DEV_FLAG_DMA_IOMMU);\n __create_dev_flag_accessors(dma_skip_sync, DEV_FLAG_DMA_SKIP_SYNC);\n __create_dev_flag_accessors(dma_ops_bypass, DEV_FLAG_DMA_OPS_BYPASS);\n __create_dev_flag_accessors(state_synced, DEV_FLAG_STATE_SYNCED);\n+__create_dev_flag_accessors(dma_coherent, DEV_FLAG_DMA_COHERENT);\n \n /**\n  * struct device_link - Device link representation.\ndiff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h\nindex edd7de60a957..44dd9035b4fe 100644\n--- a/include/linux/dma-map-ops.h\n+++ b/include/linux/dma-map-ops.h\n@@ -230,7 +230,7 @@ int dma_direct_set_offset(struct device *dev, phys_addr_t cpu_start,\n extern bool dma_default_coherent;\n static inline bool dev_is_dma_coherent(struct device *dev)\n {\n-\treturn dev->dma_coherent;\n+\treturn dev_dma_coherent(dev);\n }\n #else\n #define dma_default_coherent true\n","prefixes":["v4","7/9"]}