From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE286F36C59 for ; Mon, 20 Apr 2026 08:29:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1285509.1566514 (Exim 4.92) (envelope-from ) id 1wEk0c-0007oV-2V; Mon, 20 Apr 2026 08:29:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1285509.1566514; Mon, 20 Apr 2026 08:29:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wEk0b-0007oO-Vz; Mon, 20 Apr 2026 08:29:33 +0000 Received: by outflank-mailman (input) for mailman id 1285509; Mon, 20 Apr 2026 08:29:32 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wEk0a-0007oI-N4 for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 08:29:32 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wEk0Z-00CLEI-LQ for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 10:29:31 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69e5e3df-bab6-0a2a0a5309dd-0a2a4509bd9e-34 for ; Mon, 20 Apr 2026 10:29:31 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69e5e3eb-2497-0a2a45090019-d1558030d4fa-3 for ; Mon, 20 Apr 2026 10:29:31 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so23586705e9.0 for ; Mon, 20 Apr 2026 01:29:31 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fc1c01cfsm279130295e9.10.2026.04.20.01.29.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Apr 2026 01:29:29 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776673771; x=1777278571; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=QWTXAfMVrrFKv6Z3Kx/OO9RQJRVpKh/l9TdFSZILbWc=; b=SYruRo2OZ7H56s0zoWBDNlbAE80Xtq7H4FIOyS15EBJA1sL1+myZSEpdODM3joFATB l7RnZJC2g0SiqDazILbZ3a2/piENm+sWLE9Y3bP4h8dSVPrJ5hwuJj7lpFkRc+sX1fOn eTKmhGveEkKFeSsbk7vqZ+JYI6UUP5pdCEc8xJoJnzR0i3e2dC7Wy7iGud3uZ+mguZug cFHm3TMtDozEirqtlECOy3H1AZ+U/NauTY+O76PYcQ2MBnvqBwcF9KhA4FXHEjVdDyvo TK0nIGUiGNP+gXg3rBhiOdrFn4fCZRstfGTVqhdkoM0DDQTLvZ0B5SGPWj35+ELX5mtt R0nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776673771; x=1777278571; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QWTXAfMVrrFKv6Z3Kx/OO9RQJRVpKh/l9TdFSZILbWc=; b=mfw/qO7Ycgst6TRk7lB4xUvQyEJtrJTa2hlg6NThdtCqyjV2B7Jx+SO3onZTr4XxvR w+7VTW6ZfOvNqRQWnYe/ROahspKcoISzc6lpAH0NaaDMURT59Ivw4KCMMJRCK5VONxwF vOd/cHp+aYRYSQ+Ya994zK07fGVJnjKZGtZQAtcV4n7AyiyWdf7SFhw6xpBkcWgnV82v e6+jmERdNiPUWOBlg3Ra8fEtIg0XqrKYbTXb9gbWi7X5g1+LC1KWfYMrxLDGKCsZY5LI KoA74UXz+1jF3mkHEegN1k3ak8lTnuRm4YXSLqXeO2+uFV+jPlVlso6bviaGajBc09gp OSmA== X-Forwarded-Encrypted: i=1; AFNElJ9LrtqhFomrDmdRklglqn7AlKWFxY97OEsmbP8gR4ob2pFAA5Uf+ibyFQBceMZy7IqhQKQ741KtSEI=@lists.xenproject.org X-Gm-Message-State: AOJu0YzXZIcb5HOVr0xJSVYwSwoVUqOecNsv2/BkblDR4TnVni5L14S4 G098rbGVR4nJTER0YS+4hvAa/H3AGxo+67QPFnKCHngFSFslPNhMaaNpdJHMcy17mA== X-Gm-Gg: AeBDievEIDjXVYXG4XPx+YQIfa2kc19i4cp149xuaT2by/1Xz+F7hu5cgqu+fmD/BUY udEjCtOuPrFk27pQb0VjDI+BLOH/31JY3e4WIg9bdLW48va3DoIVC5uY2e60DRUIz4RwbprzUKy hIr5QCoCDliYWfEuCOdgckaFIKp0bs5RCA5SBsRUBvRKCPV+KcbpCdsUJgmsiUSIqLZzf1oEKqT WZvFCNZjbdiVgo2INo7CEZ6rJvoqefvAZ9jAOPvGrGAb3uNXgV4nWMCiZQ49RdMtoo6Vsl761ai SuSCvQjrbtcjDkD97VSlWNC/AcUd1KGvFCAoVRSo9OdJv5EeThhA2Hsa9/Z8z44mY08p6QpzTgy WbKszSC6OEGGQ4Q8QhdNLCkYW2yx0o3F4x1GGiamBsx01Rzl2ZVnJngpswUze3rRlr2mDQKflqz 8AbSN7TLMl0D0fUub0NOGejilMPh6mFlnbc1YmVydLzdC83fL8xHN9/1bwONlRSSfnQDSr0ECyg Phlda5bh9lTZvOwttmYWgtbvA== X-Received: by 2002:a05:600c:4707:b0:488:bfc3:efc with SMTP id 5b1f17b1804b1-488fb6e8eb5mr176572895e9.0.1776673769942; Mon, 20 Apr 2026 01:29:29 -0700 (PDT) Message-ID: Date: Mon, 20 Apr 2026 10:29:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 14/27] xen/riscv: introduce per-vCPU IMSIC state To: Oleksii Kurochko Cc: Romain Caritey , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: <8196fa8f000e384af697a44cb3d50ece966e82a7.1773157782.git.oleksii.kurochko@gmail.com> <1f5e262d-da1f-49a2-8e89-87fb714e51bf@suse.com> <2f555a8b-d058-41ca-80f8-ce3dc08edfbe@gmail.com> <9bee01f5-8275-4d8e-b217-1b2d2f8fa2e8@gmail.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz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fGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <9bee01f5-8275-4d8e-b217-1b2d2f8fa2e8@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-bad1c0/1776673771-49AB6A53-A2047AD8/0/0 X-purgate-type: clean X-purgate-size: 3587 On 17.04.2026 15:47, Oleksii Kurochko wrote: > On 4/16/26 2:31 PM, Jan Beulich wrote: >> On 14.04.2026 11:22, Oleksii Kurochko wrote: >>> On 4/2/26 1:31 PM, Jan Beulich wrote: >>>> On 10.03.2026 18:08, Oleksii Kurochko wrote: >>>>> --- a/xen/arch/riscv/imsic.c >>>>> +++ b/xen/arch/riscv/imsic.c >>>>> @@ -59,6 +59,29 @@ do { \ >>>>> csr_clear(CSR_SIREG, v); \ >>>>> } while (0) >>>>> >>>>> +unsigned int vcpu_guest_file_id(const struct vcpu *v) >>>>> +{ >>>>> + struct imsic_state *imsic_state = v->arch.imsic_state; >>>>> + unsigned long flags; >>>>> + unsigned int vsfile_id; >>>>> + >>>>> + read_lock_irqsave(&imsic_state->vsfile_lock, flags); >>>>> + vsfile_id = imsic_state->guest_file_id; >>>>> + read_unlock_irqrestore(&imsic_state->vsfile_lock, flags); >>>> >>>> What purpose does this locking have? Already ... >>>> >>>>> + return vsfile_id; >>>> >>>> ... here the value can be stale, if indeed there is a chance of races. >>>> Did you perhaps mean to use ACCESS_ONCE() here and where the value is >>>> set? >>> >>> ACCESS_ONCE() isn't guarantee only compiler re-ordering (as basically it >>> is just volatile-related stuff inisde the macros)? >>> >>> Generally, I think that that guest_file_id is needed to be updated only >>> during migration of vCPU from one pCPU to another and I expect that >>> during this migration vCPU isn't active, so no one will want to read >>> imsic_state->guest_file_id. But on the other hand, there is: >>> bool imsic_has_interrupt(const struct vcpu *vcpu) >>> { >>> ... >>> /* >>> * The IMSIC SW-file directly injects interrupt via hvip so >>> * only check for interrupt when IMSIC VS-file is being used. >>> */ >>> >>> read_lock_irqsave(&imsic_state->vsfile_lock, flags); >>> if ( imsic_state->vsfile_pcpu != NR_CPUS ) >>> ret = !!(csr_read(CSR_HGEIP) & BIT(imsic_state->guest_file_id, >>> UL)); >>> read_unlock_irqrestore(&imsic_state->vsfile_lock, flags); >>> ... >>> } >>> which I think could be called in parallel with with migration, so then >>> still lock are needed. >> >> None of this addresses my pointing out that the returned value will be >> stale by the point the caller gets to look at it. > > Yes, I agree that lock in vcpu_guest_file_id() is useless and it should > be on the caller side and used for the whole IMSIC state access. But ... > >> Which in turn raises >> said question about the use of a lock. If you read >> imsic_state->guest_file_id atomically (i.e. excluding tearing of reads), >> the value seen / used will be stale as with the lock in use. Unless of >> course there's yet another aspect hidden somewhere in what is not being >> explained. > > ... I am not sure that I get this part. > > If I am somewhere in migration code where I took write lock to update > imsic state (and of course ->guest_file_id as part of it) then if > someone else in parallel calls imsic_has_interrupt() then it won't enter > critical section where ->guest_file_id is trying to be read so no stale > ->guest_file_id will be read. Well, hence why I said "Unless of course there's yet another aspect hidden somewhere in what is not being explained." If I don't know the full picture, I can't very well judge whether a lock is needed, or whether ... > Then does it make sense to use ACCESS_ONCE() during read and write of > ->guest_file_id in such use cases? ... ACCESS_ONCE() would be enough. Jan