From patchwork Thu Apr 13 13:12:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 82954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1029557vqo; Thu, 13 Apr 2023 06:20:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bKk2peCo2GedoYkKVndaawRfcsvlEoxkNlIcIM8TE46d7zrEKlDIkx9G+K6S8Ox6vq78PM X-Received: by 2002:a4a:45c5:0:b0:53e:5698:c0d2 with SMTP id y188-20020a4a45c5000000b0053e5698c0d2mr888937ooa.7.1681392011182; Thu, 13 Apr 2023 06:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681392011; cv=none; d=google.com; s=arc-20160816; b=sEqJ9YeOoXPfbSSQK9NTzdS3zKOcwe2gMCNCaTRIzyHM3HKQ5wjqabH6yfig95qBS+ 4vPLnXCVHmPme/B/Jouzot7YavTnz4toG/L0IyUsU8p9tIwoyoTR4xQMBw1ySKyvX5Hs NGRkzhK9pvZi7qcdKQQWe5pMwDjh6QpCHeE+7ZOGQxaGerh1qTwHWpa1wAfcKv0/+VQz AbE9n0KtG6PhAmJG0dKgHXJWOlFOdgIUGUqAa6+sONCoXtG6o5ShGpS9Nm6zBGc1ZsjC E3sxbPcyAOfbnOFVVyXOvMhFxv1g+RuKXkLW3UVA7uA3iemEAKMAPRnE+OgBf0za7oUc DYuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=akxBw8gEREuaBtxzA9qIYFhL4FrjZkaJp5ikMOEw/lQ=; b=kWY3znjLeOuSzcxFpAPQe414hHvvD2ZNiRusUY5aStrhs2P1q4Nh8L7ajsXegFlv37 atnIQZ75ycB4RPHlf2A7KwQ70n75J3YdgbNz2ozP6J8sDJR+WHK5gq7jBcmAvMSFcdgM nPewiLd/RSNIPYHvtWODsKtF8Pd8MHWuXZRda2R8su9O5o0jDddjR5L3HQ9vePn5DATO 4wFBPFyVYPun3iKmPwlyDZCFKhg6S4K9H9e4nkLj9ISTHmzJxbyhH4I6miQD1hah1ZnW XJSqGNZBNO8BmphhzCjod+9lHv1N6NW7bIct6FYsulUpnuPBjtdnqoj7pW3i0kJWbQ/R j2KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eFVXlBPl; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x137-20020a4a418f000000b005423695623asi530883ooa.80.2023.04.13.06.19.57; Thu, 13 Apr 2023 06:20: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=@google.com header.s=20221208 header.b=eFVXlBPl; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbjDMNMt (ORCPT + 99 others); Thu, 13 Apr 2023 09:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbjDMNMr (ORCPT ); Thu, 13 Apr 2023 09:12:47 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467E89ECC for ; Thu, 13 Apr 2023 06:12:28 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f8e31155bso53091537b3.11 for ; Thu, 13 Apr 2023 06:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681391547; x=1683983547; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=akxBw8gEREuaBtxzA9qIYFhL4FrjZkaJp5ikMOEw/lQ=; b=eFVXlBPlk8KkE4XTi3JZp57snk+KevAS/0AAEO8KUQKSbtlezEhHzl7gM28PRSANsQ xFi584iPfUhEI0ZAWBsfzgePMg6oXen48McBe5VCcz3DplJ9+JeZD8wEHuwXfb7eY+aA THak+NvZaFjvTd+yrsI8BUdRjts/e+TlenEWbeB/fSl1rVQuPhafFd1hHa62VJ5VBcge QATR+oYNfLbD6vAsZk5H8AvFSiI2ZPTTeghUDlHrPmD8jGdiFgPB+XAQN5P+oGv4bkuy TaaeUlNPKKBSXPBJH748wRB30XE0ZCS7+rSKmlOZquvzOsUXj2WzRZH+HEGv0+px1Ego 21RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681391547; x=1683983547; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=akxBw8gEREuaBtxzA9qIYFhL4FrjZkaJp5ikMOEw/lQ=; b=iJrhHwiZV5eFXWxSRVSSGoWb4kbLl4cAglEFG1KAEVFYALRaruxvHOGBCPZo+13PIB FxQv70Z1H7mMjWzoIuAzBn8DzyqYQchumUoQrvmkzg6fptoL0BFSxDk9Y5WEskmbJ4NZ lZpxB+ypbuRehjEqsepOYzsdADpv0cJWzlFaw+be8mSSvGItAb9VX5H79zmSUBV+Wx2f R9FOuQskrTy1znTSFkvD0HkQAfBsJV3ChxgJ3/+ZhcF7/exAlIn0n32QKowe6AtqBWnb PD3TIKUIuf3LRVEQWxRv31ZTiPCxnEAbkyiip+/+zwiWPFBVS1WoXnGDeduwKimvwInz XO6g== X-Gm-Message-State: AAQBX9fzFhwly2CFsZOHqua92mYtMUHij9lUYtxY54vvLUDWy/R74GH5 k6nCnC8InK643vXhufvolRfTEZ4EFMA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:eb2b:4d7d:1d7f:9316]) (user=glider job=sendgmr) by 2002:a81:4319:0:b0:545:62cb:3bcf with SMTP id q25-20020a814319000000b0054562cb3bcfmr1362388ywa.2.1681391547580; Thu, 13 Apr 2023 06:12:27 -0700 (PDT) Date: Thu, 13 Apr 2023 15:12:20 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230413131223.4135168-1-glider@google.com> Subject: [PATCH v2 1/4] mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush() 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, Dipanjan Das X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763067309465788551?= X-GMAIL-MSGID: =?utf-8?q?1763067309465788551?= As reported by Dipanjan Das, when KMSAN is used together with kernel fault injection (or, generally, even without the latter), calls to kcalloc() or __vmap_pages_range_noflush() may fail, leaving the metadata mappings for the virtual mapping in an inconsistent state. When these metadata mappings are accessed later, the kernel crashes. To address the problem, we return a non-zero error code from kmsan_vmap_pages_range_noflush() in the case of any allocation/mapping failure inside it, and make vmap_pages_range_noflush() return an error if KMSAN fails to allocate the metadata. This patch also removes KMSAN_WARN_ON() from vmap_pages_range_noflush(), as these allocation failures are not fatal anymore. Reported-by: Dipanjan Das Link: https://lore.kernel.org/linux-mm/CANX2M5ZRrRA64k0hOif02TjmY9kbbO2aCBPyq79es34RXZ=cAw@mail.gmail.com/ Fixes: b073d7f8aee4 ("mm: kmsan: maintain KMSAN metadata for page operations") Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- v2: -- return 0 from the inline version of kmsan_vmap_pages_range_noflush() (spotted by kernel test robot ) --- include/linux/kmsan.h | 20 +++++++++++--------- mm/kmsan/shadow.c | 27 ++++++++++++++++++--------- mm/vmalloc.c | 6 +++++- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h index e38ae3c346184..c7ff3aefc5a13 100644 --- a/include/linux/kmsan.h +++ b/include/linux/kmsan.h @@ -134,11 +134,12 @@ void kmsan_kfree_large(const void *ptr); * @page_shift: page_shift passed to vmap_range_noflush(). * * KMSAN maps shadow and origin pages of @pages into contiguous ranges in - * vmalloc metadata address range. + * vmalloc metadata address range. Returns 0 on success, callers must check + * for non-zero return value. */ -void kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, - pgprot_t prot, struct page **pages, - unsigned int page_shift); +int 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. @@ -281,12 +282,13 @@ static inline void kmsan_kfree_large(const void *ptr) { } -static inline void kmsan_vmap_pages_range_noflush(unsigned long start, - unsigned long end, - pgprot_t prot, - struct page **pages, - unsigned int page_shift) +static inline int kmsan_vmap_pages_range_noflush(unsigned long start, + unsigned long end, + pgprot_t prot, + struct page **pages, + unsigned int page_shift) { + return 0; } static inline void kmsan_vunmap_range_noflush(unsigned long start, diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c index a787c04e9583c..b8bb95eea5e3d 100644 --- a/mm/kmsan/shadow.c +++ b/mm/kmsan/shadow.c @@ -216,27 +216,29 @@ void kmsan_free_page(struct page *page, unsigned int order) kmsan_leave_runtime(); } -void kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, - pgprot_t prot, struct page **pages, - unsigned int page_shift) +int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, + pgprot_t prot, struct page **pages, + unsigned int page_shift) { unsigned long shadow_start, origin_start, shadow_end, origin_end; struct page **s_pages, **o_pages; - int nr, mapped; + int nr, mapped, err = 0; if (!kmsan_enabled) - return; + return 0; shadow_start = vmalloc_meta((void *)start, KMSAN_META_SHADOW); shadow_end = vmalloc_meta((void *)end, KMSAN_META_SHADOW); if (!shadow_start) - return; + return 0; nr = (end - start) / PAGE_SIZE; s_pages = kcalloc(nr, sizeof(*s_pages), GFP_KERNEL); o_pages = kcalloc(nr, sizeof(*o_pages), GFP_KERNEL); - if (!s_pages || !o_pages) + if (!s_pages || !o_pages) { + err = -ENOMEM; goto ret; + } for (int i = 0; i < nr; i++) { s_pages[i] = shadow_page_for(pages[i]); o_pages[i] = origin_page_for(pages[i]); @@ -249,10 +251,16 @@ void kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, kmsan_enter_runtime(); mapped = __vmap_pages_range_noflush(shadow_start, shadow_end, prot, s_pages, page_shift); - KMSAN_WARN_ON(mapped); + if (mapped) { + err = mapped; + goto ret; + } mapped = __vmap_pages_range_noflush(origin_start, origin_end, prot, o_pages, page_shift); - KMSAN_WARN_ON(mapped); + if (mapped) { + err = mapped; + goto ret; + } kmsan_leave_runtime(); flush_tlb_kernel_range(shadow_start, shadow_end); flush_tlb_kernel_range(origin_start, origin_end); @@ -262,6 +270,7 @@ void kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end, ret: kfree(s_pages); kfree(o_pages); + return err; } /* Allocate metadata for pages allocated at boot time. */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index a50072066221a..1355d95cce1ca 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -605,7 +605,11 @@ int __vmap_pages_range_noflush(unsigned long addr, unsigned long end, int vmap_pages_range_noflush(unsigned long addr, unsigned long end, pgprot_t prot, struct page **pages, unsigned int page_shift) { - kmsan_vmap_pages_range_noflush(addr, end, prot, pages, page_shift); + int ret = kmsan_vmap_pages_range_noflush(addr, end, prot, pages, + page_shift); + + if (ret) + return ret; return __vmap_pages_range_noflush(addr, end, prot, pages, page_shift); } From patchwork Thu Apr 13 13:12:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 82956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1030066vqo; Thu, 13 Apr 2023 06:20:51 -0700 (PDT) X-Google-Smtp-Source: AKy350YCy4DZyQ1f8vEsunSm/WYOWRiXGe+f1TK7nVKeHs8qgsLxeJmq4YiBvecJa3Gvo5YYug76 X-Received: by 2002:a05:6870:a706:b0:187:8260:2f8 with SMTP id g6-20020a056870a70600b00187826002f8mr1760581oam.6.1681392051216; Thu, 13 Apr 2023 06:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681392051; cv=none; d=google.com; s=arc-20160816; b=TzwRc1qnLUOxDZEt4axEtctt3Tg5uCYIz40w9tgqlvIw+g9nC85mD4Nzu8J1Q6DCDc xGBITh10KSjTPNtg3qWMc77YefB1eusklxCDDf3d4JFosMS0kJwY942PM1/hbRTGWnYf GgjdJFlmXkHPpgsV+OoiDPxtHrtDrgKMhJQ/VPii0Bpy9DX5ALX4ftPwCj/btXKxc3by GqhKco+FZvuesRmvFQn84g4we9bDeAXBiCG2eBk0WfVPtbDR2q9EPY359hi9om3e44vb ykWIteRYl2am8UWbFeqxcPItJrBiBZJngz5q9p7ED+xXc66M7/laazS01JEPR7D4kzh/ tcaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=akRe6e4LluVT6nSisjA8EFH4R71lf+zwEBXmk0EhBro=; b=TDHDKHErGdl+uGTel0CpG3gK5bhHZfUz+pDN9SjkJu/xIUcwWvT3oElk+XDlVCgeih ia3Bw6M2JtPnlbKbrAiDq1ww8CAXiC7Kuqjq5+1DkLnl1GRvufmE3pm/g+nFfK5M9lrY rzDzmdRf4u2vwoay5AY+FTSph0TGUVysLL6dZahnKd4/uI/ygwUa4fzQ8SJArL8gbD9s 9VqRPKCJX055dpsykijMraCl0qHjFJiBTeGn73wqp0x7tabIu/CnRFKzqt98fzScE9B+ S1LD1907wtvEWudDhAk3aYH6cvKGbvgN/hIctweTKkKLrqByKPJz8vPMxT/DE1uAhchg hSaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UWMmjgu4; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a9d7ac9000000b0069a1c55580asi1682263otn.3.2023.04.13.06.20.38; Thu, 13 Apr 2023 06:20:51 -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=@google.com header.s=20221208 header.b=UWMmjgu4; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230367AbjDMNMv (ORCPT + 99 others); Thu, 13 Apr 2023 09:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjDMNMs (ORCPT ); Thu, 13 Apr 2023 09:12:48 -0400 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94913A26F for ; Thu, 13 Apr 2023 06:12:32 -0700 (PDT) Received: by mail-wm1-x34a.google.com with SMTP id m7-20020a05600c3b0700b003ee112e6df1so4774989wms.2 for ; Thu, 13 Apr 2023 06:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681391551; x=1683983551; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=akRe6e4LluVT6nSisjA8EFH4R71lf+zwEBXmk0EhBro=; b=UWMmjgu4IOSqX5O5xqqvwkH7RA1XeATrgudE5npO4wFN2DVyqyLAVKX22J9okhAt/f WotKPxEQVCFGgD5uRAwrTZUlIEZ/IsbLrld0fd3ZNx6+fnGYgn6BFkHWg+tR5TuM3i/2 /QxA1eaUKLWaI7yosX5HLTbRHZPPs9eytyhZr7c+VI11gRjnyGympvKbf2DjnClcTAeZ jMHfSvmsDhUshFLa9aTwnqaCvBr5xvm37uTdVsG/JwEBAxP/7+CABtpGpFdswDI8yGf6 rlZFmxJpt+if/yKAmeqXtLu4so+aQiQ3pC2KmSbses/Xm3lEXWcn2I/t7g7IAXvH2OlP 1pwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681391551; x=1683983551; 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=akRe6e4LluVT6nSisjA8EFH4R71lf+zwEBXmk0EhBro=; b=B3NdbFw02s4L3i5TT9byQml3r1lkLntpemGUL5DGE/pyVGdb4KY9hqNghDMIY5zf+6 cnf+JXu8TK3VyqxY+tbBUIqiJzzuC5oNJ87T8ptciqdIqJR9c0vm3lCjLwIKwKGZCkbl o5WXtFs8V8w1BngwPs/bhVPqK/bLdFQthUUZeeraB0QI81A+xrVBRf41d/6HgSQn6FFT IJvPmeegaIDGTErVPuZpy1ZKGTg6eUQ7qQxFXRMgoiboYDDlwVfIkSUoDtbTd40wTGna 3ZdVBSy80RBGXXjDD+CLkSupcwIzTI+Zixo6PUWdSd3rqN0/qYaye7XdjTm4xf/l1K/U MeJA== X-Gm-Message-State: AAQBX9fxbjjIvy6pE77yukuF8t8mS0NixzlsqzrvabcvUZiv6pHuWia4 TjsWpbFyRYdcZ+h6UJ3bmEk8T+J60y8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:eb2b:4d7d:1d7f:9316]) (user=glider job=sendgmr) by 2002:a5d:4a42:0:b0:2f2:7854:f419 with SMTP id v2-20020a5d4a42000000b002f27854f419mr325850wrs.13.1681391551064; Thu, 13 Apr 2023 06:12:31 -0700 (PDT) Date: Thu, 13 Apr 2023 15:12:21 +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-2-glider@google.com> Subject: [PATCH v2 2/4] mm: kmsan: handle alloc failures in kmsan_ioremap_page_range() 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, Dipanjan Das X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763067351296279223?= X-GMAIL-MSGID: =?utf-8?q?1763067351296279223?= Similarly to kmsan_vmap_pages_range_noflush(), kmsan_ioremap_page_range() must also properly handle allocation/mapping failures. In the case of such, it must clean up the already created metadata mappings and return an error code, so that the error can be propagated to ioremap_page_range(). Without doing so, KMSAN may silently fail to bring the metadata for the page range into a consistent state, which will result in user-visible crashes when trying to access them. Reported-by: Dipanjan Das Link: https://lore.kernel.org/linux-mm/CANX2M5ZRrRA64k0hOif02TjmY9kbbO2aCBPyq79es34RXZ=cAw@mail.gmail.com/ Fixes: b073d7f8aee4 ("mm: kmsan: maintain KMSAN metadata for page operations") Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- v2: -- updated patch description as requested by Andrew Morton -- check the return value of __vmap_pages_range_noflush(), as suggested by Dipanjan Das -- return 0 from the inline version of kmsan_ioremap_page_range() (spotted by kernel test robot ) --- include/linux/kmsan.h | 19 ++++++++------- mm/kmsan/hooks.c | 55 ++++++++++++++++++++++++++++++++++++------- mm/vmalloc.c | 4 ++-- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h index c7ff3aefc5a13..30b17647ce3c7 100644 --- a/include/linux/kmsan.h +++ b/include/linux/kmsan.h @@ -160,11 +160,12 @@ void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end); * @page_shift: page_shift argument passed to vmap_range_noflush(). * * KMSAN creates new metadata pages for the physical pages mapped into the - * virtual memory. + * virtual memory. Returns 0 on success, callers must check for non-zero return + * value. */ -void kmsan_ioremap_page_range(unsigned long addr, unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int page_shift); +int 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. @@ -296,12 +297,12 @@ static inline void kmsan_vunmap_range_noflush(unsigned long start, { } -static inline void 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 kmsan_ioremap_page_range(unsigned long start, + unsigned long end, + phys_addr_t phys_addr, pgprot_t prot, + unsigned int page_shift) { + return 0; } static inline void kmsan_iounmap_page_range(unsigned long start, diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index 3807502766a3e..ec0da72e65aa0 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -148,35 +148,74 @@ void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end) * into the virtual memory. If those physical pages already had shadow/origin, * those are ignored. */ -void kmsan_ioremap_page_range(unsigned long start, unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int page_shift) +int kmsan_ioremap_page_range(unsigned long start, unsigned long end, + phys_addr_t phys_addr, pgprot_t prot, + unsigned int page_shift) { gfp_t gfp_mask = GFP_KERNEL | __GFP_ZERO; struct page *shadow, *origin; unsigned long off = 0; - int nr; + int nr, err = 0, clean = 0, mapped; if (!kmsan_enabled || kmsan_in_runtime()) - return; + return 0; nr = (end - start) / PAGE_SIZE; kmsan_enter_runtime(); - for (int i = 0; i < nr; i++, off += PAGE_SIZE) { + for (int i = 0; i < nr; i++, off += PAGE_SIZE, clean = i) { shadow = alloc_pages(gfp_mask, 1); origin = alloc_pages(gfp_mask, 1); - __vmap_pages_range_noflush( + if (!shadow || !origin) { + err = -ENOMEM; + goto ret; + } + mapped = __vmap_pages_range_noflush( vmalloc_shadow(start + off), vmalloc_shadow(start + off + PAGE_SIZE), prot, &shadow, PAGE_SHIFT); - __vmap_pages_range_noflush( + if (mapped) { + err = mapped; + goto ret; + } + shadow = NULL; + mapped = __vmap_pages_range_noflush( vmalloc_origin(start + off), vmalloc_origin(start + off + PAGE_SIZE), prot, &origin, PAGE_SHIFT); + if (mapped) { + __vunmap_range_noflush( + vmalloc_shadow(start + off), + vmalloc_shadow(start + off + PAGE_SIZE)); + err = mapped; + goto ret; + } + origin = NULL; + } + /* Page mapping loop finished normally, nothing to clean up. */ + clean = 0; + +ret: + if (clean > 0) { + /* + * Something went wrong. Clean up shadow/origin pages allocated + * on the last loop iteration, then delete mappings created + * during the previous iterations. + */ + if (shadow) + __free_pages(shadow, 1); + if (origin) + __free_pages(origin, 1); + __vunmap_range_noflush( + vmalloc_shadow(start), + vmalloc_shadow(start + clean * PAGE_SIZE)); + __vunmap_range_noflush( + vmalloc_origin(start), + vmalloc_origin(start + clean * PAGE_SIZE)); } flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end)); flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end)); kmsan_leave_runtime(); + return err; } void kmsan_iounmap_page_range(unsigned long start, unsigned long end) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 1355d95cce1ca..31ff782d368b0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -313,8 +313,8 @@ int ioremap_page_range(unsigned long addr, unsigned long end, ioremap_max_page_shift); flush_cache_vmap(addr, end); if (!err) - kmsan_ioremap_page_range(addr, end, phys_addr, prot, - ioremap_max_page_shift); + err = kmsan_ioremap_page_range(addr, end, phys_addr, prot, + ioremap_max_page_shift); return err; } 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: 82977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1041119vqo; Thu, 13 Apr 2023 06:36:34 -0700 (PDT) X-Google-Smtp-Source: AKy350Z0taWCMM2J948Qz1B/sZNyDECiIub1I8WWuinvN1p4HDFceUSBrClMI052etu4BggprjWy X-Received: by 2002:a17:903:454:b0:1a6:4fbd:d5bf with SMTP id iw20-20020a170903045400b001a64fbdd5bfmr2109661plb.8.1681392993838; Thu, 13 Apr 2023 06:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681392993; cv=none; d=google.com; s=arc-20160816; b=gP2H+chMBreAqHjSZAZHc1ES7KkeOnKmxGV9tKSKKb6EiBVVomzInc9HBRrO8a8eYL kqGiQ6DTPNPCBwzfsKGhkGw4aQ5JIacfk69fl5EIwlZe94yPgeKJb8SbBWWuRHTbzhjo poLeCTeUQ6orohpRQaEfU1k98Oq5rZi2ZRIxcDzfSIm/DABXWO26HVHPQc9+0uyQiTXP +s+Eo21vkOyBF6lyZ/mRelet7B7cvOMrhISD7l0WgMZ837lQ2Dae7t3HO+MaIGYMssyq sCm5MuzLoFZUYWf1Qt6y+lAZqhaEsDD/QYH2aFDzAWu2I5i45mZ7wm3Qirj3QdQiJNCY 3qxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=BH4qKloTg3p5myDfS9qJ+XOa2IgLWTGcxSlYlXSqJNo=; b=BqzJWjEexJFlxpGaaL5WLO3WvJYGk8Wgun9qOoccU41n9O2dbBsWNlA9LboYGyt11/ OKtAQluawsrpFGUiYQlGmzBAlT1JA9z8J0owoRXUrqZuPfmGEEr8R3sHCMdHLIH06pGJ tBZEjDW1HKkUb8NhEoc9d7NDj7ZVyY4BsrFMuOspFFYN8FrO5bfdYYCWyzHlcvw+C4x9 M3HSGlu4UKC9529LNsHwM3QehLVnRnITrs9gHxr77KKBFTc9uGz8d4HinH+sz5u1CcY7 B6Dg6AwEYNOvDqTLfSjYpWZMiREDU75SpwWWPHJwIBWqgphrmbduvDYd1jFHaE5nqk/p C6Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=D1+Gxpsm; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020a1709029b8200b001a63783159csi2017307plp.238.2023.04.13.06.36.17; Thu, 13 Apr 2023 06:36:33 -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=@google.com header.s=20221208 header.b=D1+Gxpsm; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230403AbjDMNM5 (ORCPT + 99 others); Thu, 13 Apr 2023 09:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbjDMNMu (ORCPT ); Thu, 13 Apr 2023 09:12:50 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D501EA5EC for ; Thu, 13 Apr 2023 06:12:35 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id 4fb4d7f45d1cf-504c8399f19so1289773a12.0 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=Z+PI8+aF1sKXSmsAeX7NmFkD9Oe6C33iI25BGmbk0MK0XNrPiQdhErN2mBvZrZe38M rUMwRxB5Cc9r5K+Xu/NO+rEASEwEHfG2CAUIZjEjZTHtm6dntmi33mvAmX6sBF7/xYmt z5o6lRkvNB8sDKpC0j74RVy4q9CI17Iv126+p0q9MOgOVlFwK5OkrZq3hJDgIonMctHT peQR/cXZLm20g1nlxloKbsw8ZQNRhM5/FN08ErpsCgu38aC0MqXtGHgYFu8vkyzBXyuo n11yAfN0FOVln3RX2O4h7wO9bt/QPahcm9+4uRpi+9m7O3iw1kDMWvd2UsHgy2eumsP2 +Sjg== X-Gm-Message-State: AAQBX9eq9KsYNjc9uTFkYvO/gbe0fgKkBdqW0V5QcLA4lM1DxAPn7WHc /nx7SU3EzPgje2F901Zff8S/qQDDU6U= 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763068340174509068?= X-GMAIL-MSGID: =?utf-8?q?1763068340174509068?= 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; } From patchwork Thu Apr 13 13:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 82955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1030034vqo; Thu, 13 Apr 2023 06:20:48 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8v7n1Y0wGYSPjl/3eAtR6RVahvlEuGbvINf1dDsvbfid9nd/ILqQnT4N+CylWM1gEf5xa X-Received: by 2002:a05:6870:59b:b0:177:9753:f82b with SMTP id m27-20020a056870059b00b001779753f82bmr1571143oap.5.1681392048430; Thu, 13 Apr 2023 06:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681392048; cv=none; d=google.com; s=arc-20160816; b=RMMdrqy4gtqehlf6ewiN/YHahW4mJXp5u+2V2UdoQL1KtBkwxv8UtYgiP9tdPN5U/E H74wVMWRuPSvk7hnl5J7Ey2sKpMQAe8WKstClAyZgvQqrtk+4frrJVkeMwO6dWS3UsM3 JH38oU020+UhO6S3lA6kj5d85PPV/hTivddAd+CLapMPjIGd7IAapMZgJLH3W820GdkZ QW+w/zxAXFyaxSwnBPpfwrl6EYgSNhQkFRFlCfkv18LNQwqRx75fUKqyuuJO0rVxh8hD 1XfoTEQJkd+SXAY0ZMdQko5PJNXiHrDBs8M9gXZ83+6eA3zHFpK5rZQq2NTqdxY4zOpE x8Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=5hl8mLgZ8vfFyAYGSuilKL0D92tfM3tv959zGBlMPY8=; b=ZXpLpMAjJONE0vvQFccuQBFL/v86hEAGnFxFtU/NnvUXGX80vXxwHj9OQKDLAc71mZ LYaHMd3D9ov9z3ZJqjSP96oiI4e5JhzoV7jywB98cQXE1o+KBkwYtGPHaefN0l5se4QR oFEX5HFaa/4MliyzjIqLtl0UxQlii2Y8cxCAdkNb7dGjIMEySh3oL6dXXSqyQFiIKYT9 5ZArsnPKpL0tpybsiDfhreJGBm8zzFPbj312LJgKlcuAIe8f3nHLl0o0mHhy6AE5QN+U 47g5CCgWwnvHIds1OFOanIqaGVERwPESYfNAq8JP/kncYvG6nNefKsznFwKbHem2cOVH qqLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3g3kcnsZ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a0568301e6900b0069f7e4f8557si1742527otr.60.2023.04.13.06.20.35; Thu, 13 Apr 2023 06:20:48 -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=@google.com header.s=20221208 header.b=3g3kcnsZ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbjDMNNI (ORCPT + 99 others); Thu, 13 Apr 2023 09:13:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbjDMNNA (ORCPT ); Thu, 13 Apr 2023 09:13:00 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70312A5F6 for ; Thu, 13 Apr 2023 06:12:39 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id q27-20020a50aa9b000000b00505034ae370so2883120edc.3 for ; Thu, 13 Apr 2023 06:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681391558; x=1683983558; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5hl8mLgZ8vfFyAYGSuilKL0D92tfM3tv959zGBlMPY8=; b=3g3kcnsZVl5BwzCD7l2Xo768ttu3qPYULVrQMP5xF9enWn5TBU3XzrzUhG/7hwEHQA wPLn47/ryUIDarxbfs0tE7kinLwqMnxfwdQc9Q1dUN8JcWR+QRB1dpnx08/iFWkqR2Lk NNSidDbqp2G1GtnwG23rwxGljSRZFninLhww6HZAy1DTUk234ZDJBq5flP+4WWjmWQM+ 8Uix+/hEB8gXaepnyyxnUvHwpTRRtrP74mMwqCZz1CP5JVkB4+8uXG6l4d4BkgTOte8D 7KhEZEdSO9t3ZrKdlBLF64cImCAAa1EQIUDgwpJ1BLBeNAApg6yCW8UH9Z6PPH58aN5H kJPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681391558; x=1683983558; 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=5hl8mLgZ8vfFyAYGSuilKL0D92tfM3tv959zGBlMPY8=; b=OEcGR5tsYKj8P6TQO5wsBYUIHTGm0JXfSjo556OfWxx2GCOMNVcW418PlIHwGXm4lg UcVhfmhiRqQj9yQy3Uo3oCRtiNrNcYi7cquDbo5ZhkkwhIvto25RsyUUer4PFMF8jM4m EjZJS+gunNnolKMuJZrAsyGbPlZkknrBJbfoUQ7yD9L/EygmowW8OTdadAegFcEhaqjS fuqlVJRBgaz7EaYfs5dx80l0NI6mEl61OVRWj+Hxyo1shv+Kp/sQeVnHhdg+vuqjZlPB NiUyLvSNCb46XwHkK4WzCq04A1OYc2KbSCNNhEMTsxkUyfIhP6YbrbaK7GBhgtvL1ECG uO6g== X-Gm-Message-State: AAQBX9cOLnlWAdYQhb1cj2tuPQHB8tyREua2NksXCEe+8FcxKXtJYqBC WQSaVHR9PTwq6/D1K4yIP10xAATdodI= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:eb2b:4d7d:1d7f:9316]) (user=glider job=sendgmr) by 2002:a17:906:3091:b0:94a:a6ac:8a2d with SMTP id 17-20020a170906309100b0094aa6ac8a2dmr1265450ejv.13.1681391557908; Thu, 13 Apr 2023 06:12:37 -0700 (PDT) Date: Thu, 13 Apr 2023 15:12:23 +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-4-glider@google.com> Subject: [PATCH v2 4/4] mm: apply __must_check to vmap_pages_range_noflush() 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, Dipanjan Das X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763067348336060493?= X-GMAIL-MSGID: =?utf-8?q?1763067348336060493?= To prevent errors when vmap_pages_range_noflush() or __vmap_pages_range_noflush() silently fail (see the link below for an example), annotate them with __must_check so that the callers do not unconditionally assume the mapping succeeded. Reported-by: Dipanjan Das Link: https://lore.kernel.org/linux-mm/CANX2M5ZRrRA64k0hOif02TjmY9kbbO2aCBPyq79es34RXZ=cAw@mail.gmail.com/ Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- mm/internal.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 7920a8b7982ec..a646cf7c41e8a 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -833,20 +833,20 @@ size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, * mm/vmalloc.c */ #ifdef CONFIG_MMU -int vmap_pages_range_noflush(unsigned long addr, unsigned long end, - pgprot_t prot, struct page **pages, unsigned int page_shift); +int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned long end, + pgprot_t prot, struct page **pages, unsigned int page_shift); #else static inline -int vmap_pages_range_noflush(unsigned long addr, unsigned long end, - pgprot_t prot, struct page **pages, unsigned int page_shift) +int __must_check vmap_pages_range_noflush(unsigned long addr, unsigned long end, + pgprot_t prot, struct page **pages, unsigned int page_shift) { return -EINVAL; } #endif -int __vmap_pages_range_noflush(unsigned long addr, unsigned long end, - pgprot_t prot, struct page **pages, - unsigned int page_shift); +int __must_check __vmap_pages_range_noflush( + unsigned long addr, unsigned long end, pgprot_t prot, + struct page **pages, unsigned int page_shift); void vunmap_range_noflush(unsigned long start, unsigned long end);