Message ID | 20231211141929.74027-1-alexghiti@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7083703vqy; Mon, 11 Dec 2023 06:20:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/a8sExyRZAR99kME8XfzpQJffw8IzsHW/IofyjfY+i6FgWwJgbDwVqRRJK6NP7t576ZAO X-Received: by 2002:a17:90a:eb12:b0:286:6cc0:cae0 with SMTP id j18-20020a17090aeb1200b002866cc0cae0mr3285958pjz.87.1702304448595; Mon, 11 Dec 2023 06:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702304448; cv=none; d=google.com; s=arc-20160816; b=EC7eOffW6+GQ+vOpHft7rHak2fjuUnt3BsjreNcK3NGJc7y0V5Gs4zWSgxwh6nvj1E lrxo6PgqnyfzYjnKPW5QHjCMYHIhWvI3fum+ytouYkBzD0/QGm6FdtsdMncrd2AIAYwl hCd4Uk+ekyQKFixtciTZ3iya3r18onHQ7FzOWwN+U6ITUDQTtdd+mqTVtmM9lI4QbVmJ 18baJrjAtJVHxzu+xrVDTzdONzUr/E+eJmF8zWJ5FgtexevG2f6XR3pLxUmXKqpmiC4H WrajbrGEDXNrsdeCYX397XXn80ejl6+91P/Plq0iFeyp135OIq5DHlHsAbWfkTTAcmLh myZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qOlCMJwBwYnq+sc4eyv2TB9LiWqmTIQQJ4G+eSTSNEs=; fh=6HN2Dq+BbCLqpzYMU4L/roSccNo1Z/R4irFED4LfQy4=; b=zviDndmc/AxB1Ra0GzQheRXkbS+QNcPxtavO68r5/RKn5/HoZHsTIr50BWb9knEHef 1EZN1JwkJVLHdNsNrDeJiR0jBbfyZONQoUp8Qsy1H5r4q3jfw3vQDNHGbNT7XXEhFGpk QmdgXcWeV8Sg+bX+yf6ubqk02xAD1mi2xYsU3ocpBlMN4pShs9oePm000WEt/KIgdAdY FasjY8ucpkX6BzvTV4dhu2uPQjXFLtl9kI46M5nr1aPB81Csn5B9jHT376M4+0Cg1qfu zR+3ShggMTmUgpXJOchEatieR/7wnWbtSlrRjVrwe5NdnHCcl9Lk+xA+f2KB4VhQxYw/ B2+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="U4xF/Q2x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id w6-20020a17090a8a0600b00286b47270b3si7507928pjn.151.2023.12.11.06.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="U4xF/Q2x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B5B55807F49D; Mon, 11 Dec 2023 06:20:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344475AbjLKOUd (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Mon, 11 Dec 2023 09:20:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344472AbjLKOUP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 11 Dec 2023 09:20:15 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E5D19A7 for <linux-kernel@vger.kernel.org>; Mon, 11 Dec 2023 06:19:34 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b5155e154so53159615e9.3 for <linux-kernel@vger.kernel.org>; Mon, 11 Dec 2023 06:19:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702304373; x=1702909173; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qOlCMJwBwYnq+sc4eyv2TB9LiWqmTIQQJ4G+eSTSNEs=; b=U4xF/Q2xaHy3Jmkhh6gctfRueXpaFEjwk+p7JvdBvTIwgEtmVYXqR8LwgSYOHBwLn2 q6RIFJFKntZrnZyE9Kc5BD1IooCJm2PXkQdtJ4yUcsC5pI2dY92MBZQUZdkHw/gEypim ggN/Ie1T+OCvYGGCFNgg4R49oRSN6R/vN3gXB7w9KS4fuXcDjjshzKunyvu6xYDdhLkD ii3nQPwvkPKWGovSIcUP80r1ZcIerMlgyH75SBkWmvSiZuqSI03+20VVz2lC6QpHpRML 3ZmZ4HGDjdC9B0LqjfNsJVWdaRGdTul1h/HJldgcZwt8g1FEWkGSm7WmSeTjtr/BRLTB 3wKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702304373; x=1702909173; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qOlCMJwBwYnq+sc4eyv2TB9LiWqmTIQQJ4G+eSTSNEs=; b=i89d8SObZ6AreXsKtm6pMgnRURj8QzrzFY74XJubgbO7FBXP0Dxc84GntJHZtk7X+5 5WrsPbR5dgpHaUhKkyfrClfr0/xxlTBVETIKVU9ebkr3w6Ifpmfq/QVCry60+1asdi+0 S08/eq1aXOtDWzbDZwU7Bvk1C/3n5vzmkjZaRn1Au5GmIsJ6eetP+Bc+F3Q86e3FW+BZ quTrrrfNs8UJ4tQzPgmluhGiMY7Cntgaef0xhd7eOYGS7hyCzZNpnYHRP8wvqLJI8L84 8cLcb4arIzKisBfhdX7jiADsIDpIov9+gyQObQ4ksxQWw+THaSb1R2eRQHeCropCp4Au 3niQ== X-Gm-Message-State: AOJu0YzpMZ8C/RCv9+D1GhldEZ25T0R9eiI593/YrKiJvi8B5YlrdLTE U/4BhbusEB0t7mehPneYlRDF2g== X-Received: by 2002:a05:600c:1884:b0:40c:28dc:f26f with SMTP id x4-20020a05600c188400b0040c28dcf26fmr2263783wmp.36.1702304372926; Mon, 11 Dec 2023 06:19:32 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id e17-20020a05600c4e5100b0040c34cb896asm11859176wmq.41.2023.12.11.06.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:19:32 -0800 (PST) From: Alexandre Ghiti <alexghiti@rivosinc.com> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alexghiti@rivosinc.com>, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: syzbot+afb726d49f84c8d95ee1@syzkaller.appspotmail.com Subject: [PATCH -fixes] riscv: Fix wrong usage of lm_alias() when splitting a huge linear mapping Date: Mon, 11 Dec 2023 15:19:29 +0100 Message-Id: <20231211141929.74027-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 06:20:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784995589798883098 X-GMAIL-MSGID: 1784995589798883098 |
Series |
[-fixes] riscv: Fix wrong usage of lm_alias() when splitting a huge linear mapping
|
|
Commit Message
Alexandre Ghiti
Dec. 11, 2023, 2:19 p.m. UTC
lm_alias() can only be used on kernel mappings since it explicitly uses
__pa_symbol(), so simply fix this by checking where the address belongs
to before.
Fixes: 311cd2f6e253 ("riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings")
Reported-by: syzbot+afb726d49f84c8d95ee1@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-riscv/000000000000620dd0060c02c5e1@google.com/
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
arch/riscv/mm/pageattr.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
Comments
On Mon, Dec 11, 2023 at 03:19:29PM +0100, Alexandre Ghiti wrote: > lm_alias() can only be used on kernel mappings since it explicitly uses > __pa_symbol(), so simply fix this by checking where the address belongs > to before. > > Fixes: 311cd2f6e253 ("riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings") > Reported-by: syzbot+afb726d49f84c8d95ee1@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/linux-riscv/000000000000620dd0060c02c5e1@google.com/ > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> ../arch/riscv/mm/pageattr.c:311:14: warning: variable 'ret' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized] > --- > arch/riscv/mm/pageattr.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c > index fc5fc4f785c4..f5f8aa1d38d6 100644 > --- a/arch/riscv/mm/pageattr.c > +++ b/arch/riscv/mm/pageattr.c > @@ -304,9 +304,16 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, > if (ret) > goto unlock; > } > - } else if (is_kernel_mapping(start) || is_linear_mapping(start)) { > - lm_start = (unsigned long)lm_alias(start); > - lm_end = (unsigned long)lm_alias(end); > + } else { > + if (is_kernel_mapping(start)) { > + lm_start = (unsigned long)lm_alias(start); > + lm_end = (unsigned long)lm_alias(end); > + } else if (is_linear_mapping(start)) { > + lm_start = start; > + lm_end = end; > + } else { > + goto unlock; > + } > > ret = split_linear_mapping(lm_start, lm_end); > if (ret) > -- > 2.39.2 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
Hi Alexandre, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [also build test WARNING on v6.7-rc5 next-20231211] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Alexandre-Ghiti/riscv-Fix-wrong-usage-of-lm_alias-when-splitting-a-huge-linear-mapping/20231211-222156 base: linus/master patch link: https://lore.kernel.org/r/20231211141929.74027-1-alexghiti%40rivosinc.com patch subject: [PATCH -fixes] riscv: Fix wrong usage of lm_alias() when splitting a huge linear mapping config: riscv-alldefconfig (https://download.01.org/0day-ci/archive/20231212/202312120825.UkTJCa1g-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231212/202312120825.UkTJCa1g-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312120825.UkTJCa1g-lkp@intel.com/ All warnings (new ones prefixed by >>): >> arch/riscv/mm/pageattr.c:311:14: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] 311 | } else if (is_linear_mapping(start)) { | ^~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/page.h:130:2: note: expanded from macro 'is_linear_mapping' 130 | ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/mm/pageattr.c:348:9: note: uninitialized use occurs here 348 | return ret; | ^~~ arch/riscv/mm/pageattr.c:311:10: note: remove the 'if' if its condition is always true 311 | } else if (is_linear_mapping(start)) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 312 | lm_start = start; 313 | lm_end = end; 314 | } else { | ~~~~~~~ 315 | goto unlock; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 316 | } | ~~~~~~~~~~~~~~~~~ >> arch/riscv/mm/pageattr.c:311:14: warning: variable 'ret' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized] 311 | } else if (is_linear_mapping(start)) { | ^~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/page.h:130:3: note: expanded from macro 'is_linear_mapping' 130 | ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) | ^~~~~~~~~~~~~~~~~~ arch/riscv/mm/pageattr.c:348:9: note: uninitialized use occurs here 348 | return ret; | ^~~ arch/riscv/mm/pageattr.c:311:14: note: remove the '&&' if its condition is always true 311 | } else if (is_linear_mapping(start)) { | ^ arch/riscv/include/asm/page.h:130:3: note: expanded from macro 'is_linear_mapping' 130 | ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) | ^ arch/riscv/mm/pageattr.c:265:9: note: initialize the variable 'ret' to silence this warning 265 | int ret; | ^ | = 0 2 warnings generated. vim +311 arch/riscv/mm/pageattr.c 261 262 static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, 263 pgprot_t clear_mask) 264 { 265 int ret; 266 unsigned long start = addr; 267 unsigned long end = start + PAGE_SIZE * numpages; 268 unsigned long __maybe_unused lm_start; 269 unsigned long __maybe_unused lm_end; 270 struct pageattr_masks masks = { 271 .set_mask = set_mask, 272 .clear_mask = clear_mask 273 }; 274 275 if (!numpages) 276 return 0; 277 278 mmap_write_lock(&init_mm); 279 280 #ifdef CONFIG_64BIT 281 /* 282 * We are about to change the permissions of a kernel mapping, we must 283 * apply the same changes to its linear mapping alias, which may imply 284 * splitting a huge mapping. 285 */ 286 287 if (is_vmalloc_or_module_addr((void *)start)) { 288 struct vm_struct *area = NULL; 289 int i, page_start; 290 291 area = find_vm_area((void *)start); 292 page_start = (start - (unsigned long)area->addr) >> PAGE_SHIFT; 293 294 for (i = page_start; i < page_start + numpages; ++i) { 295 lm_start = (unsigned long)page_address(area->pages[i]); 296 lm_end = lm_start + PAGE_SIZE; 297 298 ret = split_linear_mapping(lm_start, lm_end); 299 if (ret) 300 goto unlock; 301 302 ret = walk_page_range_novma(&init_mm, lm_start, lm_end, 303 &pageattr_ops, NULL, &masks); 304 if (ret) 305 goto unlock; 306 } 307 } else { 308 if (is_kernel_mapping(start)) { 309 lm_start = (unsigned long)lm_alias(start); 310 lm_end = (unsigned long)lm_alias(end); > 311 } else if (is_linear_mapping(start)) { 312 lm_start = start; 313 lm_end = end; 314 } else { 315 goto unlock; 316 } 317 318 ret = split_linear_mapping(lm_start, lm_end); 319 if (ret) 320 goto unlock; 321 322 ret = walk_page_range_novma(&init_mm, lm_start, lm_end, 323 &pageattr_ops, NULL, &masks); 324 if (ret) 325 goto unlock; 326 } 327 328 ret = walk_page_range_novma(&init_mm, start, end, &pageattr_ops, NULL, 329 &masks); 330 331 unlock: 332 mmap_write_unlock(&init_mm); 333 334 /* 335 * We can't use flush_tlb_kernel_range() here as we may have split a 336 * hugepage that is larger than that, so let's flush everything. 337 */ 338 flush_tlb_all(); 339 #else 340 ret = walk_page_range_novma(&init_mm, start, end, &pageattr_ops, NULL, 341 &masks); 342 343 mmap_write_unlock(&init_mm); 344 345 flush_tlb_kernel_range(start, end); 346 #endif 347 348 return ret; 349 } 350
diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index fc5fc4f785c4..f5f8aa1d38d6 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -304,9 +304,16 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, if (ret) goto unlock; } - } else if (is_kernel_mapping(start) || is_linear_mapping(start)) { - lm_start = (unsigned long)lm_alias(start); - lm_end = (unsigned long)lm_alias(end); + } else { + if (is_kernel_mapping(start)) { + lm_start = (unsigned long)lm_alias(start); + lm_end = (unsigned long)lm_alias(end); + } else if (is_linear_mapping(start)) { + lm_start = start; + lm_end = end; + } else { + goto unlock; + } ret = split_linear_mapping(lm_start, lm_end); if (ret)