[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] xen/x86: lock cacheline for add_sized()

  • To: Juergen Gross <JGross@xxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Tue, 6 Aug 2019 08:26:54 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4XPnrEytd1dmGgLUJfhAQnFf+XA9q8rihICw7rnpfNs=; b=b8GPcq5WgjCLI1/qdA8CPV86gwLTrj5hnb2o2dSUarq04X4P0/IjhjAWZcHd/Vm4DIlrHRXpOPVkURZIcngC3AGcEzxMTPkH9/5vT/X7s+JMIaQ5Nin65anVgF4YRjtBdylMsrABKHMM7fBVqPZSb5Tj7qDkptlEJR1JyPHZQ5/HbDTWzQsou9Z804SWfUxoKEyJQYNcaz8EODElvWo87E38yZRL34+74VBZ7OvqEnnVYBZ9kM/PCOcHKPFXNkIgxPYBX3CTriqTkUMJHkMZX3gpNsZByS/3BWUzSacWsZyi7VhQGBamTyIkoIGUjQSLlYDhQansPPzdQoW35PbFNA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oSTodpcf2Nwg+TqbPo3lVHvPjuUnzU4zxLp/rF8CCEthtjOILRPICHz/MCcP17vdiYZ8Tcebgb5AIDAtR8B+4wkxEU0PXjoxMyMuFqbC7UFUXZVFYDOaNRgl6OR20iuJm3BfkQfIFWmbF8hziqzaBVm163zjDX7UuyhIW1XCGExktPUcWbzNdAh8B3uhqcrhfB2ZU3Wy6I1myVm5apTHpYBaaCEA05uAirtQWMXmUdwNacOk3/qVaAInnc5ErZoXazjbNQcPsl7P+8IA3658z3fBNoi1TCCNMTFp+EylplHuwycXixkqqpYeAKT6U836Vn9hEl/hPhPJqkqC78vDlA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Tue, 06 Aug 2019 08:31:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVTCSgB+UnTRxATECSyt7gptB4DqbtyRoA
  • Thread-topic: [PATCH] xen/x86: lock cacheline for add_sized()

On 06.08.2019 09:00, Juergen Gross wrote:
> add_sized() should use an atomic update of the memory word, as it is
> used by spin_unlock().
> With ticket locks unlocking needs to be atomic in order to avoid very
> rare races when someone tries to get the lock while the lock holder
> is just releasing it.

Considering the commit introducing the function (3c694aec08)
explicitly saying "The add is /not/ atomic" this needs more detail.
The idea behind not using a LOCKed access here was, iirc, that
no-one else could ever update the head pointer; someone trying to
acquire the lock would only write to the tail portion. But yes, I
think I can see how this was wrong: The arch_fetch_and_add() acts
on head_tail after all, not just tail.

> --- a/xen/include/asm-x86/atomic.h
> +++ b/xen/include/asm-x86/atomic.h
> @@ -21,7 +21,7 @@ static inline void name(volatile type *addr, type val) \
>   #define build_add_sized(name, size, type, reg) \
>       static inline void name(volatile type *addr, type val)              \
>       {                                                                   \
> -        asm volatile("add" size " %1,%0"                                \
> +        asm volatile("lock; add" size " %1,%0"                          \

I realize pre-existing code in our tree uses this not fully correct
form of specifying prefixes (there shouldn't really be a line
separator between prefix and main mnemonic, unless gas would refuse
assembling the result because of it wrongly thinking the prefix was
inapplicable to the insn, like is e.g. the case here and there for
the REP prefixes), but I think we should try to avoid widening the
issue. See e.g. gnttab_clear_flags() where we already have no
semicolon, and this has gone fine since around 4.2. I seem to vaguely
recall that Linux has been using this construct to avoid build issues
with some specific (Sun?) assembler.

Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.