From: Jan Beulich <jbeulich@suse.com>
To: "Jürgen Groß" <jgross@suse.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Stefano Stabellini <sstabellini@kernel.org>,
linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org
Subject: Re: [PATCH 7/7] xen/evtchn: read producer index only once
Date: Mon, 8 Feb 2021 13:23:25 +0100 [thread overview]
Message-ID: <58ec68aa-6d86-62dd-f28a-a4e5754b0fdf@suse.com> (raw)
In-Reply-To: <9d725a1b-ec8e-c078-5ec6-9c4899d4c7aa@suse.com>
On 08.02.2021 13:15, Jürgen Groß wrote:
> On 08.02.21 12:54, Jan Beulich wrote:
>> On 08.02.2021 11:59, Jürgen Groß wrote:
>>> On 08.02.21 11:51, Jan Beulich wrote:
>>>> On 08.02.2021 11:41, Jürgen Groß wrote:
>>>>> On 08.02.21 10:48, Jan Beulich wrote:
>>>>>> On 06.02.2021 11:49, Juergen Gross wrote:
>>>>>>> In evtchn_read() use READ_ONCE() for reading the producer index in
>>>>>>> order to avoid the compiler generating multiple accesses.
>>>>>>>
>>>>>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>>>>>> ---
>>>>>>> drivers/xen/evtchn.c | 2 +-
>>>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>>
>>>>>>> diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
>>>>>>> index 421382c73d88..f6b199b597bf 100644
>>>>>>> --- a/drivers/xen/evtchn.c
>>>>>>> +++ b/drivers/xen/evtchn.c
>>>>>>> @@ -211,7 +211,7 @@ static ssize_t evtchn_read(struct file *file, char __user *buf,
>>>>>>> goto unlock_out;
>>>>>>>
>>>>>>> c = u->ring_cons;
>>>>>>> - p = u->ring_prod;
>>>>>>> + p = READ_ONCE(u->ring_prod);
>>>>>>> if (c != p)
>>>>>>> break;
>>>>>>
>>>>>> Why only here and not also in
>>>>>>
>>>>>> rc = wait_event_interruptible(u->evtchn_wait,
>>>>>> u->ring_cons != u->ring_prod);
>>>>>>
>>>>>> or in evtchn_poll()? I understand it's not needed when
>>>>>> ring_prod_lock is held, but that's not the case in the two
>>>>>> afaics named places. Plus isn't the same then true for
>>>>>> ring_cons and ring_cons_mutex, i.e. aren't the two named
>>>>>> places plus evtchn_interrupt() also in need of READ_ONCE()
>>>>>> for ring_cons?
>>>>>
>>>>> The problem solved here is the further processing using "p" multiple
>>>>> times. p must not be silently replaced with u->ring_prod by the
>>>>> compiler, so I probably should reword the commit message to say:
>>>>>
>>>>> ... in order to not allow the compiler to refetch p.
>>>>
>>>> I still wouldn't understand the change (and the lack of
>>>> further changes) then: The first further use of p is
>>>> outside the loop, alongside one of c. IOW why would c
>>>> then not need treating the same as p?
>>>
>>> Its value wouldn't change, as ring_cons is being modified only at
>>> the bottom of this function, and nowhere else (apart from the reset
>>> case, but this can't run concurrently due to ring_cons_mutex).
>>>
>>>> I also still don't see the difference between latching a
>>>> value into a local variable vs a "freestanding" access -
>>>> neither are guaranteed to result in exactly one memory
>>>> access afaict.
>>>
>>> READ_ONCE() is using a pointer to volatile, so any refetching by
>>> the compiler would be a bug.
>>
>> Of course, but this wasn't my point. I was contrasting
>>
>> c = u->ring_cons;
>> p = u->ring_prod;
>>
>> which you change with
>>
>> rc = wait_event_interruptible(u->evtchn_wait,
>> u->ring_cons != u->ring_prod);
>>
>> which you leave alone.
>
> Can you point out which problem might arise from that?
Not any particular active one. Yet enhancing some accesses
but not others seems to me like a recipe for new problems
down the road.
Jan
next prev parent reply other threads:[~2021-02-08 12:33 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-06 10:49 [PATCH 0/7] xen/events: bug fixes and some diagnostic aids Juergen Gross
2021-02-06 10:49 ` [PATCH 1/7] xen/events: reset affinity of 2-level event initially Juergen Gross
2021-02-06 11:20 ` Julien Grall
2021-02-06 12:09 ` Jürgen Groß
2021-02-06 12:19 ` Julien Grall
2021-02-06 10:49 ` [PATCH 2/7] xen/events: don't unmask an event channel when an eoi is pending Juergen Gross
2021-02-08 10:06 ` Jan Beulich
2021-02-08 10:21 ` Jürgen Groß
2021-02-08 10:15 ` Ross Lagerwall
2021-02-06 10:49 ` [PATCH 3/7] xen/events: fix lateeoi irq acknowledgment Juergen Gross
2021-02-06 10:49 ` [PATCH 4/7] xen/events: link interdomain events to associated xenbus device Juergen Gross
2021-02-08 23:26 ` Boris Ostrovsky
2021-02-09 13:55 ` Wei Liu
2021-02-06 10:49 ` [PATCH 5/7] xen/events: add per-xenbus device event statistics and settings Juergen Gross
2021-02-08 23:35 ` Boris Ostrovsky
2021-02-06 10:49 ` [PATCH 6/7] xen/evtch: use smp barriers for user event ring Juergen Gross
2021-02-08 9:38 ` Jan Beulich
2021-02-08 9:41 ` Jürgen Groß
2021-02-08 9:44 ` Andrew Cooper
2021-02-08 9:50 ` Jan Beulich
2021-02-08 10:23 ` Andrew Cooper
2021-02-08 10:25 ` Jürgen Groß
2021-02-08 10:31 ` Andrew Cooper
2021-02-08 10:36 ` Jan Beulich
2021-02-08 10:45 ` Andrew Cooper
2021-02-06 10:49 ` [PATCH 7/7] xen/evtchn: read producer index only once Juergen Gross
2021-02-08 9:48 ` Jan Beulich
2021-02-08 10:41 ` Jürgen Groß
2021-02-08 10:51 ` Jan Beulich
2021-02-08 10:59 ` Jürgen Groß
2021-02-08 11:50 ` Julien Grall
2021-02-08 11:54 ` Jan Beulich
2021-02-08 12:15 ` Jürgen Groß
2021-02-08 12:23 ` Jan Beulich [this message]
2021-02-08 12:26 ` Jürgen Groß
2021-02-08 11:40 ` Julien Grall
2021-02-08 11:48 ` Jürgen Groß
2021-02-08 12:03 ` Julien Grall
2021-02-06 18:46 ` [PATCH 0/7] xen/events: bug fixes and some diagnostic aids Julien Grall
2021-02-07 12:58 ` Jürgen Groß
2021-02-08 9:11 ` Julien Grall
2021-02-08 9:41 ` Jürgen Groß
2021-02-08 9:54 ` Julien Grall
2021-02-08 10:22 ` Jürgen Groß
2021-02-08 10:40 ` Julien Grall
2021-02-08 12:14 ` Jürgen Groß
2021-02-08 12:16 ` Julien Grall
2021-02-08 12:31 ` Jürgen Groß
2021-02-08 13:09 ` Julien Grall
2021-02-08 13:58 ` Jürgen Groß
2021-02-08 14:20 ` Julien Grall
2021-02-08 14:35 ` Julien Grall
2021-02-08 14:50 ` Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58ec68aa-6d86-62dd-f28a-a4e5754b0fdf@suse.com \
--to=jbeulich@suse.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®