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

Re: [PATCH v4 14/21] x86: introduce helper for recording degree of contiguity in page tables


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 6 May 2022 15:25:53 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=U0zNji4fmI6m8Qd0nVtMxOFicFEkdsmHD2NrHiaWTF4=; b=aFzFvM2nPAARL0/Df77scVcCG/ywaDPhuI5kBhE1Rl67ZSfGaEl7BX1vJUGUARYepHPYNfbby+AIs+a7xKrTZJZtrvwzCGLtZen7kg2Dbd7licmDyYmc0UkTMK0zrIOAZyhduqgw/JXfXfHul6g6TQ++D3qp7odMp5knPN1lYrAi5P/785dnJtEtBmoHRcIHL3htO7G6SRhpGShURmjXwW32q/riZY6hVj9CyVMLqEl9sdXhbNj9LPNSq0v0HlUOwh5bWhVSQNZECKMzXQyNVvD0rkb8vOo6NfrdXaLbvVn5j96ECW7NEqZB+F3Grg3SIyq7Th6kTc67GPoXTnlKNg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BIpGKkLojpeMOsI+/KTWkKuK6nj4CPvPJBO5v0/MXr+hAllNYuYBjCHpTtXzUwvaZS249sw3eN3HHI+cgFEuuWPOJi1mbFQZ6T73Qx0/FoVByICx7mm6rejZp2Hr/QG5GFx4ti1QnpRoZkSlvXkZ/oLU9570iitIzwJ7XumSDQVBkYhRKBV8CyuJ08S+lXNYUIQF9BiI5p3WXMW57SW/bNS4IIH5QvTssR8dm4+Gg7YiNVd11fD1MDnjBT0UqBab3+U5ZGrQYVBwqpsE9dbtMNsOy2zwituLrVGzesf0qKpL8iv8O3GazmySwIZRV9F6Az7xgcaQtxgzG07XYh30Cg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 06 May 2022 13:26:15 +0000
  • Ironport-data: A9a23:tQsa3a2GSaHLeBRA5PbD5alwkn2cJEfYwER7XKvMYLTBsI5bpzZTm zBJDTjXOvfeY2HwKosgYYW+8BtT7cPcxoVgTwM+pC1hF35El5HIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkjk7xdOCn9xGQ7InQLlbGILes1htZGEk1EU/NtTo5w7Rj2tMw34Dga++wk YiaT/P3aQfNNwFcagr424rbwP+4lK2v0N+wlgVWicFj5DcypVFMZH4sDfjZw0/DaptVBoaHq 9Prl9lVyI97EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPg/W+5PwZG8O4whlkeydx /0O6r2wVl4PEJfu2/k/cDx+OQR/HZx/reqvzXiX6aR/zmXgWl61mbBCKR9zOocVvOFqHWtJ6 PoUbigXaQyOjP63x7T9TfRwgsMkL4/gO4Z3VnNIlGmFS6p5B82SBfyVube03x9p7ixKNezZa McDLyJmcTzLYgFVO0dRA5U79AutrianLGYF9g/EzUYxy2fZliJw25bxCcGLRdOgBsdexkm6+ H2TqgwVBTlfbrRz0wGt8Hihm+vOliPTQ58JGfuz8fsCqE2ewCkfBQMbUXO/oOKlkQiuVtRHM UsW9yEy668o+ySDVtDgWzWorXjCuQQTM/JPF8Uq5QfLzbDbizt1HUABRz9FLdAj6sk/QGVw0 kfTxoy1QztyrLeSVHSRsK+Oqi+/MjQUKmlEYjIYSQwC4J/op4RbYg/zc+uP2ZWd1rXdcQwcC RjTxMTir93/VfI26pg=
  • Ironport-hdrordr: A9a23:DPIzDKDZbZ0RreDlHej0sseALOsnbusQ8zAXPh9KJyC9I/b2qy nxppgmPEfP+U0ssQIb6Kq90ci7MD7hHPtOgLX5Uo3SJTUO1FHYTr2KjrGSjwEIeReOjtK1vJ 0IG8MVZb2AbmSS5vyKhDVQZuxQpuVvh5rY4ts2oU0dKD1CWuVF1UNUGwybGkp5SE1tHpwiDq eR4cJBun6JZWkXRt7TPAhLY8Hz4/nw0L72ax8PABAqrCOUiymz1bL8Gx+Emj8DTjJ0x6s4+2 StqX222kzjiYD79vbv7R6R031koqqi9jKFPr3ItiEhEESttu9vXvUkZ1TNhkFznAjl0idWrD CFmWZdAy000QKWQoj9m2qS5yDwlDkp8HPs0lmenD/qptH4XiszD45biZteaQax0TtpgDjS6t M444u1jesgMfr7plW12zEIbWAeqmOk5X451eIDhX1WVoUTLLdXsIwE5UtQVJMNBjjz5owrGP RnSJi03ocdTXqKK3TC+mV/yt2lWXo+Wh+AX0gZo8SQlzxbhmpwwUcUzNEW2n0A6JU+QZ9Z4P msCNUiqJheCssNKa5tDuYIRsW6TmTLXBLXKWqXZU/qEakWUki93KLf8fEw/qWnaZYIxJw9lN DKWFZVsmM7YAb1BdaP0IcO8hfWXW27Vzioysw23ekJhlQ9fsueDcSuciFcryL7mYRhPiTyYY fCBK5r
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Apr 25, 2022 at 10:41:23AM +0200, Jan Beulich wrote:
> This is a re-usable helper (kind of a template) which gets introduced
> without users so that the individual subsequent patches introducing such
> users can get committed independently of one another.
> 
> See the comment at the top of the new file. To demonstrate the effect,
> if a page table had just 16 entries, this would be the set of markers
> for a page table with fully contiguous mappings:
> 
> index  0 1 2 3 4 5 6 7 8 9 A B C D E F
> marker 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0
> 
> "Contiguous" here means not only present entries with successively
> increasing MFNs, each one suitably aligned for its slot, but also a
> respective number of all non-present entries.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> v3: Rename function and header. Introduce IS_CONTIG().
> v2: New.
> 
> --- /dev/null
> +++ b/xen/arch/x86/include/asm/pt-contig-markers.h
> @@ -0,0 +1,105 @@
> +#ifndef __ASM_X86_PT_CONTIG_MARKERS_H
> +#define __ASM_X86_PT_CONTIG_MARKERS_H
> +
> +/*
> + * Short of having function templates in C, the function defined below is
> + * intended to be used by multiple parties interested in recording the
> + * degree of contiguity in mappings by a single page table.
> + *
> + * Scheme: Every entry records the order of contiguous successive entries,
> + * up to the maximum order covered by that entry (which is the number of
> + * clear low bits in its index, with entry 0 being the exception using
> + * the base-2 logarithm of the number of entries in a single page table).
> + * While a few entries need touching upon update, knowing whether the
> + * table is fully contiguous (and can hence be replaced by a higher level
> + * leaf entry) is then possible by simply looking at entry 0's marker.
> + *
> + * Prereqs:
> + * - CONTIG_MASK needs to be #define-d, to a value having at least 4
> + *   contiguous bits (ignored by hardware), before including this file,
> + * - page tables to be passed here need to be initialized with correct
> + *   markers.

Not sure it's very relevant, but might we worth adding that:

- Null entries must have the PTE zeroed except for the CONTIG_MASK
  region in order to be considered as inactive.

> + */
> +
> +#include <xen/bitops.h>
> +#include <xen/lib.h>
> +#include <xen/page-size.h>
> +
> +/* This is the same for all anticipated users, so doesn't need passing in. */
> +#define CONTIG_LEVEL_SHIFT 9
> +#define CONTIG_NR          (1 << CONTIG_LEVEL_SHIFT)
> +
> +#define GET_MARKER(e) MASK_EXTR(e, CONTIG_MASK)
> +#define SET_MARKER(e, m) \
> +    ((void)((e) = ((e) & ~CONTIG_MASK) | MASK_INSR(m, CONTIG_MASK)))
> +
> +#define IS_CONTIG(kind, pt, i, idx, shift, b) \
> +    ((kind) == PTE_kind_leaf \
> +     ? (((pt)[i] ^ (pt)[idx]) & ~CONTIG_MASK) == (1ULL << ((b) + (shift))) \
> +     : !((pt)[i] & ~CONTIG_MASK))
> +
> +enum PTE_kind {
> +    PTE_kind_null,
> +    PTE_kind_leaf,
> +    PTE_kind_table,
> +};
> +
> +static bool pt_update_contig_markers(uint64_t *pt, unsigned int idx,
> +                                     unsigned int level, enum PTE_kind kind)
> +{
> +    unsigned int b, i = idx;
> +    unsigned int shift = (level - 1) * CONTIG_LEVEL_SHIFT + PAGE_SHIFT;
> +
> +    ASSERT(idx < CONTIG_NR);
> +    ASSERT(!(pt[idx] & CONTIG_MASK));
> +
> +    /* Step 1: Reduce markers in lower numbered entries. */
> +    while ( i )
> +    {
> +        b = find_first_set_bit(i);
> +        i &= ~(1U << b);
> +        if ( GET_MARKER(pt[i]) > b )
> +            SET_MARKER(pt[i], b);

Can't you exit early when you find an entry that already has the
to-be-set contiguous marker <= b, as lower numbered entries will then
also be <= b'?

Ie:

if ( GET_MARKER(pt[i]) <= b )
    break;
else
    SET_MARKER(pt[i], b);

Thanks, Roger.



 


Rackspace

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