From patchwork Sat Nov 30 00:14:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13889014 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 F020DD735EA for ; Sat, 30 Nov 2024 00:14:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 655D66B0083; Fri, 29 Nov 2024 19:14:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6045B6B0085; Fri, 29 Nov 2024 19:14:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CBA86B0088; Fri, 29 Nov 2024 19:14:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2FBA36B0083 for ; Fri, 29 Nov 2024 19:14:32 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 13A6D1215F6 for ; Sat, 30 Nov 2024 00:14:31 +0000 (UTC) X-FDA: 82840839732.15.FEBEA2F Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 9CB0F120018 for ; Sat, 30 Nov 2024 00:14:16 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="WpVj/PWZ"; spf=pass (imf29.hostedemail.com: domain of 341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732925663; 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: references:dkim-signature; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=rmOSfNDllECvlVze21o5cItCoLdTjFi/qwN3V/+CnvuSWm0dyzvuIyxYcebzWvlaryDg2X 8Y6h1EZt/98TZy1hsh1/vWFtuCytyx2q4nojxr0ipvrL4J7/KaEFtRnw/S6DLyxXsU19yM OVFZ/0hm6SblO1ewuJnY894rZV1CzWI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732925663; a=rsa-sha256; cv=none; b=3erTLvq2JR9M+xEKVf24wwyJLFyolrVxbXD92Cn4kNIA6UI7c9kkYyThamFuLMU+21Ft0e zNcxNjYqlMbXd18s7nqE73zp2Weyb7PtcP/ChgeuNCVxlwwaaDJbLesORzvRdOhgYs/Pnp gNbLJGhTSt4560u7Wyx2fdo88SFEvzg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="WpVj/PWZ"; spf=pass (imf29.hostedemail.com: domain of 341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=341hKZwYKCP4y0xkthmuumrk.iusrot03-ssq1giq.uxm@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f72112de23so1667698a12.1 for ; Fri, 29 Nov 2024 16:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732925668; x=1733530468; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=WpVj/PWZux/spyJjxNmJQ5W3qMwoiX/uC1a5M0wLOKA4Elt0/J8FfFpoA41SuKVfmW RfHlntpOV9+xqr9BMTsx7yKHnAcZhEIMgyY08tKnlP7+vGEyaE/Dn7uqJvjf2rYoo1wt UdEbR4kE58KA0ldRULMu+tG3N7lRMWg4iN5tn82Wc2rKr2Bj5uEbWuVmFUcjBX/o0ZUn iBzcaAS+GXGL6wM/nEI8evnxpzHsZsAunamZltn6wA4Cm/kVwdXBuLJb1MHlsK2QqLGG o8kJaOffwBJr4TzJXxA1HucJAL2XRVt7IQDGdX10cHu4PSvfzPg6wWEIrLyCsvUhJMvW WgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732925668; x=1733530468; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Msn5ydSsXJvK7W3o2JvmJ38LPMa5eKoJY2o5aCZVyQY=; b=v2yPId64v4naztLWsVy8Ntvthsy7sQUg3YW8uEzZ+RW/H3MrZos7RBdA7EYrApAiSI qo0M0jhQnv/XwCAX4509xk94T7/1Z4DG7z/7ins5l2dLzkvVDewdjGFh8W4hOBX5mLRK q5f/YIDN4L+DM0XkZ2jdm0DxP7iNqGGrjUG1/wJnb1Pz5kY7M1UKPGzCDFbPZr2uREEM SKBTvVIUoM8aAk9ErSE4gPAZkqpnzYceQRFkMsme94MV3nOTBZsiDkIDnUnieQqsjKGn 33jq4Rt/XuhpEMBThlRZ9r+BBd8In7ztGEpV08XGKmvaWx6cO2q5yLo2GdbgShQ2izP5 /59A== X-Forwarded-Encrypted: i=1; AJvYcCVupg/o78LMidzFDXQXIK3JCkZ6j9lnXd6PdyMlQQoksNwAxeB4WNe+d8RQD2oq06MtqXPgTQiVKQ==@kvack.org X-Gm-Message-State: AOJu0YwgU40pp3eFYCpprfzYXF+Lx8iUukLpf0ixx9g72GmaJmMrk/tv QXGruwC2K28NaWIK1okb5a3b/0xgRqfiZ27v14EtdXaNy9uc/2cPId9X2ZyuVaiWDAskWG8cm+Q 4nA== X-Google-Smtp-Source: AGHT+IEZ5ARDUBAksQwZjcJ+vr4ytuA3q37Am5GZLCfm/nnP/vqItHhnwL+g58/Cgk/lpSFI0Dl6QgR1MCA= X-Received: from pfaw9.prod.google.com ([2002:a05:6a00:ab89:b0:724:fde8:58a]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a10f:b0:1e0:cc21:19a2 with SMTP id adf61e73a8af0-1e0e0aaf55bmr19045608637.1.1732925667676; Fri, 29 Nov 2024 16:14:27 -0800 (PST) Date: Fri, 29 Nov 2024 16:14:22 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241130001423.1114965-1-surenb@google.com> Subject: [PATCH 1/2] alloc_tag: fix module allocation tags populated area calculation From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, pasha.tatashin@soleen.com, rppt@kernel.org, yuzhao@google.com, souravpanda@google.com, 00107082@163.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com, kernel test robot X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9CB0F120018 X-Stat-Signature: nzciyeos1pzstk8wi61zhgyn4c54f77a X-Rspam-User: X-HE-Tag: 1732925656-417610 X-HE-Meta: U2FsdGVkX1/ug+BCozMGMA26aFTAdPYXRr3lCM5ILoWNq3bNOwPqCqjxeSzL3BiyNmz9yZ/1c54L1C3pp9B2pPGwBd3aNbt4GDdX7b0mcYVqhNH6RA1MmARkcLwCcQYcK+Cnn/M6gwxhQDOdRUmRwwaUuQz/5506/AX3SyhU+vSEVsY2emZe7ZH5j9BNkCdP6UxZrpzD/B6DsCwcggqBnlS4EZoL0+QIp4nz/k9U+IDe+yX/6YgE5nkALrBFdKpdmcdfSYIGVdGZurc3R5be1s0t8sZi+t8/QzRDC8Dm7gY9CKRT4fapc8U+MywUY5GmxGz+5xjF70KPvYjfSQBOcAunFTOaeFKfOuXpmRw6FSjh7ePvSKE+VpbxXja40Q9oqVaC5iLRKhJ0+4Gd/2IdBtRl9frpUAsjZzA4tAQJM/aFOg69lOkBrmYsAH3yRYWxSieAiN9LeCFdfWFUJFJ7ajBTqI00UVEwMrt/cC6ajavWs4i6VflrjhzxEev/VIQv3f4Kz7scy9EZuQ1GUSuXaM0VlGFG8eyGkVq/Oi/xJTnhe5rRxxcBf/sowZEatjaO6bIV94sXrSODBVShrsB/qQsWsOKr+PijUJzw3jRkmA9DSpKWapbJjKr/+JY2unZ31ByI419kYkt2WuwdzBLLoeRFs8fH5++cHkNC4v1Al9mFrrZGQnh17n8J65K+IwhPRrrgxijTirzn59kHjCobCT1KHUpzyrHN/5TP282Mz2I04/jC4jQndtpQI6RlH01mckPxD0ZskXjn4Z4niDJ0lKuIzkmlsrj+v8Iu0V+mV+DWHr1c9HRUxadaJyOPVMQW/iJecNGXqFXp+b4A9vwMmsOt+I79L7EFSZj0AJr9SidAGYNn99q7VLRzWxwvbY/Ne/n6ZTzo/UmInF1SM35fXTAlG8KoP6xMEpxQaDQ0OBwxamsglZ1mAk9r+eoJ9EYaxLekkN1yqmwn+G4vi4K 5aX1pco+ aoKi1pbHgStkVrZj6GPYXGT24/VMXK4DYi/IRBpz471SV+7XwsC0KoKsp0qjeZQWtTEnmRCBQOtQY4UeANGHXP2VNYgxWaV9ddQ6y1FnPb/iIzKHDPHy+uQKhP9D9dXHQ9vJUiQDnweG92M+2W9ZUWUnxWAV8J27l0b91YArYd8fgdBZhcZ6zXNTyZd09Zc5yubqFx923I19ptgxc2WfKpaif2yr/qxzhakEMtDI4UNXsQsYUrplBnHgy4jGlHNh9TnPcLaDHPN7i28q4ezuc+SX6kED8R/BuUbSceCj9fekLnYA/PcKF0621vUJVE9QV47P7vppSQMLHYWosbvmWEvKBjocYt94uV4c8MSmEXursYwa+bxEbfCvtNw6va/+35YEBWi7RWs8YTeGo35YImrCl+on7g2mvIgsiVO9qDYWeb/A4LxJTW+Z9rwEbV3V6k6jnH+M1ye7VZYoi80yN0un8yqKyIVramvJ1VvvM0XzyK1LxxgkbDYXUrEAp81w6O5Tk3TEKcaBF1rZ33I4SalQ4NocjAOZm91I0sggCr96Agp4ng66yUGCHRol5sDdfPy+mOZmLhOV9qVmZCn/EOTJ8llHmkXGP4y3MxdsnxrHC6w/rZh2RhMZVeINrDFnTi4Cp 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: List-Subscribe: List-Unsubscribe: vm_module_tags_populate() calculation of the populated area assumes that area starts at a page boundary and therefore when new pages are allocation, the end of the area is page-aligned as well. If the start of the area is not page-aligned then allocating a page and incrementing the end of the area by PAGE_SIZE leads to an area at the end but within the area boundary which is not populated. Accessing this are will lead to a kernel panic. Fix the calculation by down-aligning the start of the area and using that as the location allocated pages are mapped to. Fixes: 0f9b685626da ("alloc_tag: populate memory for module tags as needed") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202411132111.6a221562-lkp@intel.com Signed-off-by: Suren Baghdasaryan --- Applies over mm-unstable lib/alloc_tag.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) base-commit: 539cd49425a4e9a66d601d9a8124f5c70e238d56 diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 2414a7ee7ec7..668c4e128fa4 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -393,19 +393,20 @@ static bool find_aligned_area(struct ma_state *mas, unsigned long section_size, static int vm_module_tags_populate(void) { - unsigned long phys_size = vm_module_tags->nr_pages << PAGE_SHIFT; + unsigned long phys_end = ALIGN_DOWN(module_tags.start_addr, PAGE_SIZE) + + (vm_module_tags->nr_pages << PAGE_SHIFT); + unsigned long new_end = module_tags.start_addr + module_tags.size; - if (phys_size < module_tags.size) { + if (phys_end < new_end) { struct page **next_page = vm_module_tags->pages + vm_module_tags->nr_pages; - unsigned long addr = module_tags.start_addr + phys_size; unsigned long more_pages; unsigned long nr; - more_pages = ALIGN(module_tags.size - phys_size, PAGE_SIZE) >> PAGE_SHIFT; + more_pages = ALIGN(new_end - phys_end, PAGE_SIZE) >> PAGE_SHIFT; nr = alloc_pages_bulk_array_node(GFP_KERNEL | __GFP_NOWARN, NUMA_NO_NODE, more_pages, next_page); if (nr < more_pages || - vmap_pages_range(addr, addr + (nr << PAGE_SHIFT), PAGE_KERNEL, + vmap_pages_range(phys_end, phys_end + (nr << PAGE_SHIFT), PAGE_KERNEL, next_page, PAGE_SHIFT) < 0) { /* Clean up and error out */ for (int i = 0; i < nr; i++) From patchwork Sat Nov 30 00:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13889015 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 B32F6D735E4 for ; Sat, 30 Nov 2024 00:14:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 803A36B0085; Fri, 29 Nov 2024 19:14:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B1E76B0088; Fri, 29 Nov 2024 19:14:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62B7E6B0089; Fri, 29 Nov 2024 19:14:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 45EA36B0085 for ; Fri, 29 Nov 2024 19:14:33 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C6F83C1110 for ; Sat, 30 Nov 2024 00:14:32 +0000 (UTC) X-FDA: 82840839648.06.1DED33E Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 2563B140018 for ; Sat, 30 Nov 2024 00:14:24 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=A6d3k2rh; spf=pass (imf23.hostedemail.com: domain of 35VhKZwYKCAIuwtgpdiqqing.eqonkpwz-oomxcem.qti@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=35VhKZwYKCAIuwtgpdiqqing.eqonkpwz-oomxcem.qti@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732925667; 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=EpxKrm09+SAPJmqxiOga34L0FlTVIOyjiLSP0mnmo8Q=; b=4ZSAk/Nwtau601Dpnz6A87hFAj+D9vzr2QoZVPiBCRzlKpVg4pGoPJTlOKfNZ0tbtbo7iC lJ7KpVlWbviMGl6t4Ci1vwN2KawJp32Yk6ScD6H1PNbDhsmM1xHCQ5LBF1YyO+3q1wB/23 bv5ldKyIBTIJ0LTrEKH4txNyA+swfjs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=A6d3k2rh; spf=pass (imf23.hostedemail.com: domain of 35VhKZwYKCAIuwtgpdiqqing.eqonkpwz-oomxcem.qti@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=35VhKZwYKCAIuwtgpdiqqing.eqonkpwz-oomxcem.qti@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732925667; a=rsa-sha256; cv=none; b=ABzOPte4XNtUjE/+Kt/6QP0XEu+0XppUHgkABzMExp+MOEwfegN/eHM1sFL1lRjrBPCrAF L3V48BQ+5EzggI0o3YpjLgkF5x+yQdTsbMhbukBX5Sk6lg0Kzci2MB5xfGtuClcwDZas12 hl1noUKZ4WVgZ5s/rIS/tBD22XOANKg= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7fb96d3a3a8so1700339a12.1 for ; Fri, 29 Nov 2024 16:14:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732925670; x=1733530470; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EpxKrm09+SAPJmqxiOga34L0FlTVIOyjiLSP0mnmo8Q=; b=A6d3k2rhbfE0TD4NSWbPTcXNH3s5v0ZtxthzEpGrsNAnp8MymvzQHC1AcvTfoZDtUB 1jo/FpVe9+BpyBdnuHfKDmPy271By9xlobs6CUXYZYvQqFkwZ/MscZmX1Eg4KcsQV8Va mIDx4FiaBt4cFkfkA/btIfySUJ3rjh3DhRJGbSXVkviy2jbVDip6nHn/mAIR3qgYWlLf F/Zph+1Fa1K6sRk423itY9PhnDvleXaI9mxDmeHy2o8ofCMo/5mjNlHbUOdd5if98Ppp 59nb2TwgB3+xPmNaMQs/VvqIMlvRJ661wYs2Sc+kMUSnl3bweqmTMHqRFydUNr8rbFI6 NEiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732925670; x=1733530470; 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=EpxKrm09+SAPJmqxiOga34L0FlTVIOyjiLSP0mnmo8Q=; b=dzJKe4V1iN9QcyRN9VQuvgtHixzCIav99A+Svm9eN+Gy86pyzNn3UVxKzHrBXfjvWY z+B7GaOla60F+94cjzKctD6bmp7LY5yXW6TBTjGjUgBiwkWI6FFoIehJNDhVnqsNAg3N 6RL/OehWPyBiMWTP3bG/gpLcVkZGh4ongFltC5PSbRrp/6enboyulRIvIvxJ/VDVJlRI oC6Cs77KHXse3Z212ZFXNhrO0O9D4pC+WoVc2HoFaf0g5EuQdcQRE6cCEz6qCWpfKymz xp+p5ARvAbKAlKS4LCvNr3I54xvjWfd2nGBjWUmedKMcSoYnJAwPgfGEL4qy9dYpZkAN +hjA== X-Forwarded-Encrypted: i=1; AJvYcCVA3QCilMPXGqZpcHxGbLq4SfwtjRQX2K5oTUXZwJmSGMd9bzSGGSkykSb09dZF5B95LosRexrOGA==@kvack.org X-Gm-Message-State: AOJu0Yz/YWQVna5OEHkwBGWnqlLNbIBZsJ4xrg0iLhXNGIiuLvhRo8Qv z0NaZG2NWnoEPsnEbVFwuS6PKMgFMXs7vXhx5EoskHCLjZbXMLg8xNyfI0ANlWY7YwUu4MFZ6II V0A== X-Google-Smtp-Source: AGHT+IEO1jq34I3S812cs/LC0CKsK8aw91gm2TSktbeu+lByPR5ov0es7eD7kBYzK9Z3arRorDrO9sMmpoc= X-Received: from pgvz26.prod.google.com ([2002:a65:665a:0:b0:7ea:618a:6e04]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:99a5:b0:1e0:df27:10b8 with SMTP id adf61e73a8af0-1e0e0b52839mr22679442637.31.1732925669775; Fri, 29 Nov 2024 16:14:29 -0800 (PST) Date: Fri, 29 Nov 2024 16:14:23 -0800 In-Reply-To: <20241130001423.1114965-1-surenb@google.com> Mime-Version: 1.0 References: <20241130001423.1114965-1-surenb@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241130001423.1114965-2-surenb@google.com> Subject: [PATCH 2/2] alloc_tag: fix set_codetag_empty() when !CONFIG_MEM_ALLOC_PROFILING_DEBUG From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, pasha.tatashin@soleen.com, rppt@kernel.org, yuzhao@google.com, souravpanda@google.com, 00107082@163.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspamd-Queue-Id: 2563B140018 X-Stat-Signature: 8uxzt39b5at7pux4i1tuzhd1yqceaeke X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1732925664-725272 X-HE-Meta: U2FsdGVkX1+xdP5mLhp/V973MKFIH8GWIcJgSC0nuY+I1oEXjs2cobyZA3++RHn/53Q2grsVKS46snLbM85SyY98DLPgdiEnt6qqQVDtFJqrTiRfW8ajHbDtfV1ivCnfeWVY8CiH5RMlW397A1ilhiMdJPRWXwWgvE9OeyCOOVr5fyrNRKz4mP24GWkhHqjkGN4Td62u1oopNRe6QGPD9VBDRDty7au7DklKuxFJOauYg69UnPwIEhmfVPF6k+uxiKOFBSH3cU6KxwUj5v6Ph7GKJ8wJ2TdRmeZceXV3qTThafZVLneL2b4xyrQO4uLkzJ6aArEb4bp8WAEFP+vVnE+0wU0jLnwDmRCIMCmUSJYH4WASgtU2YVFlwEf3okdi6RmI6HXP/5dj+QBl1uY4F81LHB87wtpbtK1FXGZAaV4EY3ZeryDJOsADnXBJ12e/yDJKgNNySFw49MrmVL40CJpqiRTQU4oq3XwtMNM8MS9NEfPinY/Fl1+CgrW0HS/Wawo5hcReMpZvN0OETsQHoljYlh+n5wcYcz+0dweKKHQ/1FOY84Ge/Qt/65TXGdIys2OSMfYB095cSJ0m/oT0tmKa05mvg0ueFdN/KX2WhNpbBHgbt6OyfNBMq7LmxLUZLt08SeYHherRLCKu13oZjQJmWe1yVhFgEk5/FQfBQNHlLk6RpVw6LlY7hHiL0T5hrrUw4TxkAw/mAzyo6TCGuTRMSxxfuJ0nRi991wXb5gKeLVNt5wNllcdZoMmpT6zDgbs8F1InT7j71j2PMDB2drxRIfq3fxZ7J/p9rol5+nQIfi/gSMpPzWT+ymLFNzeljogbMmU5Pp4EGSIXGknwVJWWXhfjUKxDyuzijOq4CrTYvXNe2Ql+hwwzsoC0yXyh2tP2Ks/boYH17XWPAB+8p+/BHHtGNOc295KuAjzbM+qfES8upfxKBMfULyGGTlyvSIpAyNU1E+lFsBYsjQ6 hCqaF6iW tz35j96DA96JIIz2K2xaxooxcdXyYnYi1uPEvt6VJQ+QmIrcWxzxf4YGNS7V4bg3O9sjF/1rkMScrorc9a419C4GACICrLUJVMgOIZhS3Pyexh1Wsp0A0/U5pHcH2wjdq+oyqisR41aDhUaxxUD7HHSfYBVn9mRUoGl01KbIdVKwpdVyRhMj0zbrhw+XJJm+MEEJ8TI1dkwy2Xg7JrUGHgIC88SqfH5KndGRRfQ/xjd89Ox6YnWiH+Yd1UjB9kDtqtluMgH7PM6CwyEpiMdLsa6bpeSN//hDRV6Tso0Fo3atVdCkLDlqPR+sw92bq8e/z5yf5XbvcbxrcFnIQ9PbJ6rlZdVEdUREeFeILqJyaxgPYIfYUeBa6YhPemeJeIvSKDjk0BzwZ2M0kggAxrI0idRyRz32uPdgIE4QDUxj7lmy2OF8w5OVe15GJSYAJvQcbsQd5Ge0xNP0RT4nkwQVTDINjOEEYu2HCv5XfKRQV2zH9MPs1mDcFB08TOgQrPC31hRLwhf/uWtbovpRCMshaxkpyC8yODEPcK53ls2d0x1J+76KgZ+P7BHA0itioB7ovErHERWyNSGlhoFMth5FBfCbovHSSvGGBzQiCIK32PGrolAfz7SFprT8Xd86RWwNkvzkKydWqtLzGimt7+t4ejBBH89+4eXe88WJeU4QLS0TQ0ueeyFnjGY5YtSPnMI1OOCaPBY62Jvujy9eWloHynhXlUSlw6v8l/I0QAcCvh5P96bDMJqBc3O+NQ49u7F4LYW4q X-Bogosity: Ham, tests=bogofilter, spamicity=0.031133, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: It was recently noticed that set_codetag_empty() might be used not only to mark NULL alloctag references as empty to avoid warnings but also to reset valid tags (in clear_page_tag_ref()). Since set_codetag_empty() is defined as NOOP for CONFIG_MEM_ALLOC_PROFILING_DEBUG=n, such use of set_codetag_empty() leads to subtle bugs. Fix set_codetag_empty() for CONFIG_MEM_ALLOC_PROFILING_DEBUG=n to reset the tag reference. Fixes: a8fc28dad6d5 ("alloc_tag: introduce clear_page_tag_ref() helper function") Reported-by: David Wang <00107082@163.com> Closes: https://lore.kernel.org/lkml/20241124074318.399027-1-00107082@163.com/ Signed-off-by: Suren Baghdasaryan --- Applies over mm-unstable include/linux/alloc_tag.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 7c0786bdf9af..f6a1b73f5663 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -63,7 +63,12 @@ static inline void set_codetag_empty(union codetag_ref *ref) #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline bool is_codetag_empty(union codetag_ref *ref) { return false; } -static inline void set_codetag_empty(union codetag_ref *ref) {} + +static inline void set_codetag_empty(union codetag_ref *ref) +{ + if (ref) + ref->ct = NULL; +} #endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */