Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1469459iob; Sat, 14 May 2022 09:49:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxP79Iubc6dUZleZHJbViKQtjdbz/0JR7UXWS+7kIQ8iVboOHAxc+zosqskj1WWFeU0MZlF X-Received: by 2002:a05:6402:1a36:b0:425:f96c:350f with SMTP id be22-20020a0564021a3600b00425f96c350fmr4643485edb.160.1652546951259; Sat, 14 May 2022 09:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652546951; cv=none; d=google.com; s=arc-20160816; b=Ajfo/CxyxSGG4eXLPaVf1GHuqFF9l9MOEtVgdlSXsjLH3/s76XgpE/EcPzT3L46uI8 QV+9xrLEf2QVqgMpYE3E/3l4cXx78JBUh37Oyz4bKddtkmIYIPxDjMiUi4vWZKtBdpEX RfLFRpSJRgfU2YtgfcjEbqspNIZl06zWFM9OtzHI3nrC31773hNKaHNsYto+VZfmCGas mYenzwB2tNGj7deuyWR65HwxaJ7TQJbHj8H6P/P0wBUYcE1ubvwGmj09m89ks5AzUpUt uo5EQ2U+GWvJNtr+qADniGdLDxz4z4yLf9L5zGUJ7G/ik+QZiZk7SVKLyyosKIeX3n28 JSDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language:cc:to :subject:from:user-agent:mime-version:date:message-id:dkim-signature; bh=Li6/tQDXHzv8kZiOpKUQD1TPJCVlsntTcNVJC7DZIzE=; b=We/EhcBzFYS2Anha9Qqn0vivk0LpvjmRpIyNx2Q93QdZGGmkFgL6oBx4h0C51kzfye wNhrej56NpaqnsLhS5ZNaevXtUcGnMRhbU1BBZ9eHRR85JQX+ydKD/clbCwC/gJMsQwE 4Zt+i4U6+UGp1/dFR9XjbISeAtgHRVzmhx8rSwD00/buwOtWnyoMx0/E2TlmyqXy6jmf eksCBtJHO69Hzt2Z0Z6PNhbqyrbq0zy3KTKElx9QkBBivTIeGyIBevXL+uAXUCahDbH3 HCDcwLpzmb3pWxYohhgLbzHMjldHQBenHS+HcehjWPDLK04bEPY76OZ8RW1M9j9+gB0Q lD9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=Kotfmd59; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn18-20020a1709070d1200b006e87fcf4cc5si2706026ejc.734.2022.05.14.09.48.45; Sat, 14 May 2022 09:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=Kotfmd59; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233239AbiENO0j (ORCPT + 99 others); Sat, 14 May 2022 10:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbiENO01 (ORCPT ); Sat, 14 May 2022 10:26:27 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7763ADF84 for ; Sat, 14 May 2022 07:26:24 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id b18so18941895lfv.9 for ; Sat, 14 May 2022 07:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :content-language:content-transfer-encoding; bh=Li6/tQDXHzv8kZiOpKUQD1TPJCVlsntTcNVJC7DZIzE=; b=Kotfmd59T2vwKoH6qJP7H7l9uJqBl4fvklMdaJmEksj2Hc2/NE0Q/bFCFcQRipTg50 gWoPxS8tp+9YBXdLbEdFKp4dNu3+ECSYOiv3E63hYcBSm4oEHOtgE1TIAjkYkXu4c0zV QFoLt5LtKLO/qBTEJ0e566ZyqeuGymbwkbwq1HnmkuMnOzDvFvrJRKmYmhD5tD1gwleZ KBvcKVuZZlEFwkqsdsTIzRn9ByRm81I5XWGw0FrSFGjv25l1dzLHqhMwD+XSV3hTE6lQ ssPP6XT1mDkzEUND+/7zc84awYm1BczkR73aLT5GUdQHzSsgP2RYrAJiTAODHffOGiz9 Ytzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:content-language:content-transfer-encoding; bh=Li6/tQDXHzv8kZiOpKUQD1TPJCVlsntTcNVJC7DZIzE=; b=2HlqaMZRFi5NoImDnrwKRBF+INrkO+yOr7N/Kv6z6pBT7I5ZfWt/Gh19Szjl8bcLrd a0kjWbrpu4z2sLNvCoKtuHj8fwKx/8X9NXgWk/yYNbBAWanpMSPBPynoLbgmypf8m0Dl AUuYbwqgn9S2S0OmGiMA0ETAsPmQiA7qc/p4L+re/MN6fiHPURsh3moSOFFyJXiJWJBS Ugux+pKo9fp1uAJ9sAdQa5YuSTVvcoY+Qu0nHpEE317w+rd6A08UPrwIUX96EX5nQvLH L8f8edBEOL4yxcFazpRottHElGyCtN+i67A6BnM9VMFhSOqNLMoAcomyOjjBmIx5lI/z AiLQ== X-Gm-Message-State: AOAM531rReKn+MGtJ7sCawEFBbh7j4nfPty1QyH0fDI9nk7UKeayk6OL 3VkQLP4bFvCR7ktQnSUnv77FwQ== X-Received: by 2002:a05:6512:a92:b0:45c:6b70:c892 with SMTP id m18-20020a0565120a9200b0045c6b70c892mr1034464lfu.124.1652538382834; Sat, 14 May 2022 07:26:22 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id d15-20020ac25ecf000000b0047255d210f7sm727847lfq.38.2022.05.14.07.26.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 May 2022 07:26:22 -0700 (PDT) Message-ID: Date: Sat, 14 May 2022 17:26:21 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 From: Vasily Averin Subject: [PATCH] sparse: use force attribute for vm_fault_t casts To: Dan Williams , Matthew Wilcox , Jan Kara , Alexander Viro Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-fsdevel@vger.kernel.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes sparse warnings: ./include/trace/events/fs_dax.h:10:1: sparse: got restricted vm_fault_t ./include/trace/events/fs_dax.h:153:1: sparse: got restricted vm_fault_t fs/dax.c:563:39: sparse: got restricted vm_fault_t fs/dax.c:565:39: sparse: got restricted vm_fault_t fs/dax.c:569:31: sparse: got restricted vm_fault_t fs/dax.c:1055:41: sparse: got restricted vm_fault_t [assigned] [usertype] ret fs/dax.c:1461:46: sparse: got restricted vm_fault_t [usertype] ret fs/dax.c:1477:21: sparse: expected restricted vm_fault_t [assigned] [usertype] ret fs/dax.c:1518:51: sparse: got restricted vm_fault_t [assigned] [usertype] ret fs/dax.c:1599:21: sparse: expected restricted vm_fault_t [assigned] [usertype] ret fs/dax.c:1633:62: sparse: got restricted vm_fault_t [assigned] [usertype] ret fs/dax.c:1696:55: sparse: got restricted vm_fault_t fs/dax.c:1711:58: sparse: got restricted vm_fault_t [assigned] [usertype] ret vm_fault_t type is bitwise and requires __force attribute for any casts. Signed-off-by: Vasily Averin --- fs/dax.c | 22 +++++++++++----------- include/linux/mm_types.h | 30 ++++++++++++++++-------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 67a08a32fccb..eb1a1808f719 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -560,13 +560,13 @@ static void *grab_mapping_entry(struct xa_state *xas, if (xas_nomem(xas, mapping_gfp_mask(mapping) & ~__GFP_HIGHMEM)) goto retry; if (xas->xa_node == XA_ERROR(-ENOMEM)) - return xa_mk_internal(VM_FAULT_OOM); + return xa_mk_internal((__force unsigned long)VM_FAULT_OOM); if (xas_error(xas)) - return xa_mk_internal(VM_FAULT_SIGBUS); + return xa_mk_internal((__force unsigned long)VM_FAULT_SIGBUS); return entry; fallback: xas_unlock_irq(xas); - return xa_mk_internal(VM_FAULT_FALLBACK); + return xa_mk_internal((__force unsigned long)VM_FAULT_FALLBACK); } /** @@ -1052,7 +1052,7 @@ static vm_fault_t dax_load_hole(struct xa_state *xas, DAX_ZERO_PAGE, false); ret = vmf_insert_mixed(vmf->vma, vaddr, pfn); - trace_dax_load_hole(inode, vmf, ret); + trace_dax_load_hole(inode, vmf, (__force int)ret); return ret; } @@ -1458,7 +1458,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, void *entry; int error; - trace_dax_pte_fault(iter.inode, vmf, ret); + trace_dax_pte_fault(iter.inode, vmf, (__force int)ret); /* * Check whether offset isn't beyond end of file now. Caller is supposed * to hold locks serializing us with truncate / punch hole so this is @@ -1474,7 +1474,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, entry = grab_mapping_entry(&xas, mapping, 0); if (xa_is_internal(entry)) { - ret = xa_to_internal(entry); + ret = (__force vm_fault_t)xa_to_internal(entry); goto out; } @@ -1515,7 +1515,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, unlock_entry: dax_unlock_entry(&xas, entry); out: - trace_dax_pte_fault_done(iter.inode, vmf, ret); + trace_dax_pte_fault_done(iter.inode, vmf, (__force int)ret); return ret; } @@ -1596,7 +1596,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, */ entry = grab_mapping_entry(&xas, mapping, PMD_ORDER); if (xa_is_internal(entry)) { - ret = xa_to_internal(entry); + ret = (__force vm_fault_t)xa_to_internal(entry); goto fallback; } @@ -1630,7 +1630,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, count_vm_event(THP_FAULT_FALLBACK); } out: - trace_dax_pmd_fault_done(iter.inode, vmf, max_pgoff, ret); + trace_dax_pmd_fault_done(iter.inode, vmf, max_pgoff, (__force int)ret); return ret; } #else @@ -1693,7 +1693,7 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t pfn, unsigned int order) put_unlocked_entry(&xas, entry, WAKE_NEXT); xas_unlock_irq(&xas); trace_dax_insert_pfn_mkwrite_no_entry(mapping->host, vmf, - VM_FAULT_NOPAGE); + (__force int)VM_FAULT_NOPAGE); return VM_FAULT_NOPAGE; } xas_set_mark(&xas, PAGECACHE_TAG_DIRTY); @@ -1708,7 +1708,7 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t pfn, unsigned int order) else ret = VM_FAULT_FALLBACK; dax_unlock_entry(&xas, entry); - trace_dax_insert_pfn_mkwrite(mapping->host, vmf, ret); + trace_dax_insert_pfn_mkwrite(mapping->host, vmf, (__force int)ret); return ret; } diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8834e38c06a4..57cc4918b1b1 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -745,20 +745,22 @@ enum vm_fault_reason { VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \ VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK) -#define VM_FAULT_RESULT_TRACE \ - { VM_FAULT_OOM, "OOM" }, \ - { VM_FAULT_SIGBUS, "SIGBUS" }, \ - { VM_FAULT_MAJOR, "MAJOR" }, \ - { VM_FAULT_WRITE, "WRITE" }, \ - { VM_FAULT_HWPOISON, "HWPOISON" }, \ - { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \ - { VM_FAULT_SIGSEGV, "SIGSEGV" }, \ - { VM_FAULT_NOPAGE, "NOPAGE" }, \ - { VM_FAULT_LOCKED, "LOCKED" }, \ - { VM_FAULT_RETRY, "RETRY" }, \ - { VM_FAULT_FALLBACK, "FALLBACK" }, \ - { VM_FAULT_DONE_COW, "DONE_COW" }, \ - { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" } +#define faultflag_string(flag) {(__force unsigned long)VM_FAULT_##flag, #flag} + +#define VM_FAULT_RESULT_TRACE \ + faultflag_string(OOM), \ + faultflag_string(SIGBUS), \ + faultflag_string(MAJOR), \ + faultflag_string(WRITE), \ + faultflag_string(HWPOISON), \ + faultflag_string(HWPOISON_LARGE), \ + faultflag_string(SIGSEGV), \ + faultflag_string(NOPAGE), \ + faultflag_string(LOCKED), \ + faultflag_string(RETRY), \ + faultflag_string(FALLBACK), \ + faultflag_string(DONE_COW), \ + faultflag_string(NEEDDSYNC) struct vm_special_mapping { const char *name; /* The name, e.g. "[vdso]". */ -- 2.31.1