Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp723263lqo; Fri, 10 May 2024 12:48:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURhi6QU9HyGIU23T+WypOXiQPZcdmrK2dDuqLPeVHhamNhiCC435CDMkZBzu+Oa75f8fdvB2f679XPaEDrHNXRQI7VWWat58GzmB9pAA== X-Google-Smtp-Source: AGHT+IHt6mTY2FpFqxdA5B87lVAn/dTKcLZTkSx3pZoVEbgV6kO/SKZgmVJ7jlgcgM4A79v4L3rK X-Received: by 2002:a17:902:d2c9:b0:1e3:f4f1:a2c4 with SMTP id d9443c01a7336-1ef44050d4bmr45221085ad.64.1715370508192; Fri, 10 May 2024 12:48:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715370508; cv=pass; d=google.com; s=arc-20160816; b=SrOYkIW/GpKy1D14QgSihw2btsQ6RbO8FWKCvoMJG3hVjaMJIkMpoSJ2l3Oqdk1Jip UWZ23zmeZt9o9UTDOxMh3xCaNnyaDWdPQVxLJCqVYY2dNcstOqK9wJ1e7S1yZ8SR2PVE Np4ompYidEQUTUUlSm671DLMkg240Fxn+07Ij019VuKGeAkbmSToEeWtyeEmtomSQY3M yQgtRfDV1cenrJ8IgJJrCMJD/1TNE9lUHhvhD1Ddszun0oNGrebOfE2+1jYqBCHtWzS5 rzy/jK9PNjqkHW+kP3RQURS8J95OG0FvGT4nTYFisfqFQUh6+8gsASP6bCPSuKLh2tV8 dzwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=rRb3Y6zs6nsnzmTOAg6rQyi2criMCHD4xiIkyIgdhzA=; fh=mWT129CLdEZfS7uVg6YdmzAjX2NlzcunlPTFmZ5Fit4=; b=CqpJhdlugE5GCzjmRsoZlWgUlN+e/yZbOxdnKNzdwx4Hmvq9qyh1yp7tfuNl2nwo/R MpQ2McDtJJS7MV2dlHobqoIziwM97cJDYG8rPHkt8fMlnOsFP+3xDb48LPGpWPx25nHa 6/wUeiUOsLyrygaOftVBNk58RXdktInGGr6nHcyhmceKFXd6FMEZ73z4vZ8nojR3uqrw fP2C288+ocCQILzrAQGqhZPICjiyxKV4g9BA8TZVUR8MpdlzlgGPJOLKJyAnOHbwBXCs YMYXOGxr/hR9gPeGa0Lzewdm4vOqga6ZqlSiuYec7DNDRDSRpRffCZBu/wd1C6+eCFwr b5aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hJX3BQXB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-176150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf319d1si43941835ad.323.2024.05.10.12.48.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 12:48:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hJX3BQXB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-176150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C7981288E09 for ; Fri, 10 May 2024 19:48:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8634A4CB28; Fri, 10 May 2024 19:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hJX3BQXB" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33E334317E for ; Fri, 10 May 2024 19:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715370499; cv=none; b=UFlj8s80iRaQDzLi3NV6ixpUBFoql+FL2sOit3Cd4m2qQbS+z6dh+kYI60sP8EODhK/frY2am2e20BjaU62m9JdWHYY/G/CgO4OgcXML+SY7liiP8t3r0TTmkiGU/sUFmKrhMNmAvIqrtfvZ12qXerYdRQdqrBZKkj2g31k01Bg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715370499; c=relaxed/simple; bh=CMiGL2sWd2aGfbdzvEKmNZY9N4FQgtR15I4ohL35fkM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=G/6CqFaixvUcLqTqvqG4ujAYBFXBwxGZAggAV4Ey2wfEnEEe5JG0pzSPK/XELh4BqAeZfW3InHJ57xYu1x+GwSIg2xRsQBlX1wT5WKL+XECj1YGZdsUpx0Exuk+GoGmPQJ8jL2M4k+G2/rEPqnnNAuyZxp0vI+UV2TcaIreElYo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hJX3BQXB; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715370498; x=1746906498; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=CMiGL2sWd2aGfbdzvEKmNZY9N4FQgtR15I4ohL35fkM=; b=hJX3BQXBU1S9o3o/QEODwapJ+1HgO/mimDGFYdWP6pgSGLSMYyOkxMea 89VSYcJCGwyJ/yqIFL4tuqWQNL2paNxj+z9QBhUho29ZEV0Ery8XfpIom i0bPEy46JmOKOi6/wB+UxkclxOLt0hc+fjvmk+wZzXYN2e9G73aPXWgZy eDRDV8ZksZdzx75y9arVeqW2NQVebRMVfcKdQxeD20KBtlhGGqbr2vxkB fJb/YQMbzjrCuD9Gz101uvGvzagzxsRFOkWkhusCWWckfEdUgNyQnGN57 hxGkLXBXNkdGNFKIo2MhM8SHp40ZIsg1kedS0hia5TVMrdPNjI4ylzU/T w==; X-CSE-ConnectionGUID: 1fAO1QqWSfyVB5drgf4bmg== X-CSE-MsgGUID: +U0zX3mqSVy5s2A92YucXw== X-IronPort-AV: E=McAfee;i="6600,9927,11069"; a="11534167" X-IronPort-AV: E=Sophos;i="6.08,151,1712646000"; d="scan'208";a="11534167" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2024 12:48:18 -0700 X-CSE-ConnectionGUID: f/ugZBk2QXGZrOQ7kSzH3w== X-CSE-MsgGUID: UkmdNvhORKeQLtMkM2bQlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,151,1712646000"; d="scan'208";a="29662577" Received: from viggo.jf.intel.com (HELO [127.0.0.1]) ([10.54.77.144]) by fmviesa008.fm.intel.com with ESMTP; 10 May 2024 12:48:15 -0700 Message-ID: Date: Fri, 10 May 2024 12:48:15 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] x86/vector: Fix vector leak during CPU offline To: Dongli Zhang , x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, Borislavbp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, joe.jin@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev References: <20240510190623.117031-1-dongli.zhang@oracle.com> From: Dave Hansen Content-Language: en-US Autocrypt: addr=dave.hansen@linux.intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA/UORQWa1NiAftEoSpk5+nUUi0WE+5DRm0H+TXKBWMGNCFn c6+EKg5zQaa8Kqym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YepWpRGBIAu3bK8eXtyvrw1igWTNs2wazJ71+0z2jMzbclKAyRHKU9JdN6Hkkgr 2nPb561yjcB8sIq1pFXKyO+nKy6SZYxOvHxCcjk2fkw6UmPU6/j/nQlj2lfOAgNVKuDLothI xzi8pndB8JjuKktE5HJqUUMXePkAYIxEQ0mMc8Po7tuXdejgPMwgP7x65xtfEqI0RuzbUioF ltsp1jUaRwQZMTsCeQDdjpgHsj+P2ZDeEKCbma4m6Ez/YWs4+zDm1X8uZDkZcfQlD9NldbKD JEXLIjYWo1PHhYepSffIWPyvBMBTW2W5FRjJ4vLRrJSUoEfJuPQ3vW9Y73foyo/qFoURHO48 AinGPZ7PC7TFvUaNOTjKedrqHkaOcqB185ahG2had0xnFsDPlx5y In-Reply-To: <20240510190623.117031-1-dongli.zhang@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/10/24 12:06, Dongli Zhang wrote: > } else { > + /* > + * This call borrows from the comments and implementation > + * of apic_update_vector(): "If the target CPU is offline > + * then the regular release mechanism via the cleanup > + * vector is not possible and the vector can be immediately > + * freed in the underlying matrix allocator.". > + */ > + irq_matrix_free(vector_matrix, apicd->prev_cpu, > + apicd->prev_vector, apicd->is_managed); > apicd->prev_vector = 0; > } I know it's just two sites, but I'd much rather spend the space on a helper function than a copy-and-pasted comment. Wouldn't something like this make it like stupidly obvious what's going on: if (cpu_online(cpu)) { ... } else { irq_matrix_free_offline(apicd->prev_cpu, apicd->prev_vector, apicd->is_managed); apicd->prev_vector = 0; } /* Free a vector when the target CPU is offline */ static void irq_matrix_free_offline(...) { lockdep_assert_held(&vector_lock); WARN_ON_ONCE(!cpu_offline(apicd->prev_cpu)); /* * The regular release mechanism via the cleanup vector is not * possible. Immediately free the vector in the underlying * matrix allocator. */ irq_matrix_free(&whatever, cpu, vector, managed); } It would also be rather hard to screw up even if someone called it on an online CPU because you'd get a nice warning.