From patchwork Thu Apr 13 13:12:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13210283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B33EDC77B61 for ; Thu, 13 Apr 2023 13:12:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 506BD900007; Thu, 13 Apr 2023 09:12:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B742900002; Thu, 13 Apr 2023 09:12:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37E43900007; Thu, 13 Apr 2023 09:12:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 296F6900002 for ; Thu, 13 Apr 2023 09:12:39 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C21F31C5C60 for ; Thu, 13 Apr 2023 13:12:38 +0000 (UTC) X-FDA: 80676407196.11.03A5F4A Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf03.hostedemail.com (Postfix) with ESMTP id C0B7620024 for ; Thu, 13 Apr 2023 13:12:35 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=D1+Gxpsm; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3wv83ZAYKCMkv0xst6v33v0t.r310x29C-11zAprz.36v@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3wv83ZAYKCMkv0xst6v33v0t.r310x29C-11zAprz.36v@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681391555; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BH4qKloTg3p5myDfS9qJ+XOa2IgLWTGcxSlYlXSqJNo=; b=fqXkMEK6b0GlRB4SZ1PJwlJKGNGBMBmMuOtMjGClryCBtV397KDMseZpydIlEzJ/OkzyXi +w7SnqqSfff+gOMSLL3+0KVcH7hEfDVjeiwegpH7IJ+Mnc5qgXSdMxk+oERODPyVsXraEz rYQs2n28rxDdd5cF1MTv+Icl3Ft7ORM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=D1+Gxpsm; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3wv83ZAYKCMkv0xst6v33v0t.r310x29C-11zAprz.36v@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3wv83ZAYKCMkv0xst6v33v0t.r310x29C-11zAprz.36v@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681391555; a=rsa-sha256; cv=none; b=k30mo8MqynRYSoqHn0enY+FZv5mEM9ZLszkD7y04MCXObYXj5OWBe6AaKSqLPyHprgsQLn q8q665Z5uCxnJmdDioGfX/TUOxgvYhdOzbQshtasrkmWn2KcIN7p6vQcdTEkttVpqbGemg 94PuWDqXVRs/m2nOAhkbAAPZUi5M4wk= Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-50508242889so790667a12.1 for ; Thu, 13 Apr 2023 06:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681391554; x=1683983554; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BH4qKloTg3p5myDfS9qJ+XOa2IgLWTGcxSlYlXSqJNo=; b=D1+Gxpsma/kKehsYuehV5AlXbCxc9+6yPgVnS4mtrcrcUcfPbXHC2IVd4NdgcWvxKa sFORPx9k38EwNTdIx61YKgywtcophMGlm0SneHUBf4hypraueUI/TCDxI29jaZxY1vIy ltbilESRPv7Q0LzZkEMlnMV0LuOIkteNE9tSmGodmB8jIC9XLr/RqiX83LjxWJDm0fVC EzV7E9dIAd5BiJZP+J1mqdK7NdGn/rWTij/eOFuQ+J2dgfLFHk6TbzlAIkaBXBH7NQT0 efLIkeRRi5i07YY6nTPb/kS2kA4Hs5mxoljJv1OfBU3BsRfbtn2Ns7T6FwUjRXC1Rn46 5MNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681391554; x=1683983554; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BH4qKloTg3p5myDfS9qJ+XOa2IgLWTGcxSlYlXSqJNo=; b=GAkj4oPQfDEzjor4SbKtvPRtEJWW2ATpn06uwK6CRJ3OM3ZqkUqdgicuVJki9ODCAT yd+LhF6GXE+5ONKD9IEnL+PSkCRVXVNQXAOZvPIQy+sfs6QMqraQ9v5fHgn0cRVzn1L4 rJeVLX6DE+pZO5NMSMBoivXhLGSoej8TNBgwSeHeikp9FZXnhT2WPEJ7QdZ3aKYFhRqs 7lJ7AiqtC2NMvABUoM3hM/T27W5uuWzbc4+k6X1bL++k9/DufIsPj7IPwqOsz5ihTSuP 0L1MylckjD1Cn4KUdo7ghf6pZrNBVdR9QHhTBe5hcTCL42PJ4ssoIlL6yF3ymQjZoSuB +dOw== X-Gm-Message-State: AAQBX9cclG4rFGeKpGdczkM7qhAmyVv0hDLdlqa0VjKiy+NdE4HqXLFa 6HJdKtu+hBWarXcsL6o88g91bbl3GH0= X-Google-Smtp-Source: AKy350YjqcoIpDQnhokGemab6QINRaBafWRCSTgHRnGh9LmJmojNFRKF3kptG318ucQsrxRVaIe1NJVIppQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:eb2b:4d7d:1d7f:9316]) (user=glider job=sendgmr) by 2002:a50:9ee7:0:b0:505:842:37b0 with SMTP id a94-20020a509ee7000000b00505084237b0mr1236251edf.3.1681391554378; Thu, 13 Apr 2023 06:12:34 -0700 (PDT) Date: Thu, 13 Apr 2023 15:12:22 +0200 In-Reply-To: <20230413131223.4135168-1-glider@google.com> Mime-Version: 1.0 References: <20230413131223.4135168-1-glider@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230413131223.4135168-3-glider@google.com> Subject: [PATCH v2 3/4] mm: kmsan: apply __must_check to non-void functions From: Alexander Potapenko To: glider@google.com Cc: urezki@gmail.com, hch@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C0B7620024 X-Stat-Signature: bmoxi99qybfsixbkqqjhjeq7a8bt1uf7 X-HE-Tag: 1681391555-917440 X-HE-Meta: U2FsdGVkX1/KAdiwdAJ/9P+Mf1I09tUMPkdWmHp9nmiqHlQ1woBCE4DfIYCF8Wjp0+OQGzV6zGx0ZqxPFyW7ud3rCHyNWBGOjcwleKB0fq8VSljOVFHf60ntouEpOvIFx3EscvAlEJXi+StDixkW1a+0KszWoB8QU3c5rHewSmJRrVef78MchZzuYLZoeMNZoUJ8EV0l5P8gFrkI/NaLaZkdZVPcFUnI460m4JhRZEHXa4fOgsu65q1ph2wsaip/L+TWsTlUBEl0m7IQtzKTcxcAVyu2pz97PNRWEq8y2Nt0ZrHPRWxX5MZRrdEY+uDh4GnA/Oxf60o1bZlaGUP1pLxtk4327tPAFI4c0zaCQcra1Mo4nV1mTXfQ55FSv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EuAb0pqgy2eeyGoz/a0niMY835fHjFvFzW/oqgJREThAeQAgONod38VfKxNCXbiD5yb9X/v98+Z2PHBR26/clP+EzlrqBrqqM9HiNN4KOMDLODKQu3lhRvuT6bAMEIW4QKXNnL/IrUevTwB59SGmGjSap7xWKsrtpnr7Eo8tRXw416LJcuNK++m1gkf3vbd0uP2EaNI/oukSr5kjSbwn3N5E= 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: Non-void KMSAN hooks may return error codes that indicate that KMSAN failed to reflect the changed memory state in the metadata (e.g. it could not create the necessary memory mappings). In such cases the callers should handle the errors to prevent the tool from using the inconsistent metadata in the future. We mark non-void hooks with __must_check so that error handling is not skipped. Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- include/linux/kmsan.h | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h index 30b17647ce3c7..e0c23a32cdf01 100644 --- a/include/linux/kmsan.h +++ b/include/linux/kmsan.h @@ -54,7 +54,8 @@ void __init kmsan_init_runtime(void); * Freed pages are either returned to buddy allocator or held back to be used * as metadata pages. */ -bool __init kmsan_memblock_free_pages(struct page *page, unsigned int order); +bool __init __must_check kmsan_memblock_free_pages(struct page *page, + unsigned int order); /** * kmsan_alloc_page() - Notify KMSAN about an alloc_pages() call. @@ -137,9 +138,11 @@ void kmsan_kfree_large(const void *ptr); * vmalloc metadata address range. Returns 0 on success, callers must check * for non-zero return value. */ -int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, - pgprot_t prot, struct page **pages, - unsigned int page_shift); +int __must_check kmsan_vmap_pages_range_noflush(unsigned long start, + unsigned long end, + pgprot_t prot, + struct page **pages, + unsigned int page_shift); /** * kmsan_vunmap_kernel_range_noflush() - Notify KMSAN about a vunmap. @@ -163,9 +166,9 @@ void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end); * virtual memory. Returns 0 on success, callers must check for non-zero return * value. */ -int kmsan_ioremap_page_range(unsigned long addr, unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int page_shift); +int __must_check kmsan_ioremap_page_range(unsigned long addr, unsigned long end, + phys_addr_t phys_addr, pgprot_t prot, + unsigned int page_shift); /** * kmsan_iounmap_page_range() - Notify KMSAN about a iounmap_page_range() call. @@ -237,8 +240,8 @@ static inline void kmsan_init_runtime(void) { } -static inline bool kmsan_memblock_free_pages(struct page *page, - unsigned int order) +static inline bool __must_check kmsan_memblock_free_pages(struct page *page, + unsigned int order) { return true; } @@ -251,10 +254,9 @@ static inline void kmsan_task_exit(struct task_struct *task) { } -static inline int kmsan_alloc_page(struct page *page, unsigned int order, - gfp_t flags) +static inline void kmsan_alloc_page(struct page *page, unsigned int order, + gfp_t flags) { - return 0; } static inline void kmsan_free_page(struct page *page, unsigned int order) @@ -283,11 +285,9 @@ static inline void kmsan_kfree_large(const void *ptr) { } -static inline int kmsan_vmap_pages_range_noflush(unsigned long start, - unsigned long end, - pgprot_t prot, - struct page **pages, - unsigned int page_shift) +static inline int __must_check kmsan_vmap_pages_range_noflush( + unsigned long start, unsigned long end, pgprot_t prot, + struct page **pages, unsigned int page_shift) { return 0; } @@ -297,10 +297,11 @@ static inline void kmsan_vunmap_range_noflush(unsigned long start, { } -static inline int kmsan_ioremap_page_range(unsigned long start, - unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int page_shift) +static inline int __must_check kmsan_ioremap_page_range(unsigned long start, + unsigned long end, + phys_addr_t phys_addr, + pgprot_t prot, + unsigned int page_shift) { return 0; }