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

Re: [XEN][PATCH v3] xen/x86: guest_access: optimize raw_x_guest() for PV and HVM combinations


  • To: Grygorii Strashko <grygorii_strashko@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Fri, 7 Nov 2025 13:44:04 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=epam.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=HUAxSaDX2yP+SkUAcyXal3ROpsr3pIZuBD/6lf0Pgx8=; b=AEEizmI/K1UpiEpA6kWbpmTUHMxjiuPwZRoQZzGGF9ee7pjrmlXuBogkJnfubxuEAeIBd0tCribV935BpnDBFRIxSA2zGobu2kgUNvF65irbcQrzoFD3Y4/HhFp0FCPF7tZh3pRF9g0a6MwoFmju9vitLmPcIHNmFRp9xjkd7HRKZkhBAu1LW+r2hmchirxIQ6SCzWg5a6N6lKVUO60SimhYRLa4NdMIxLLF6WzSkO8kJVoP9x13Hy9zDBuQD4kRnGL4uvKGJeVnF76Fj24cjJCsFh8Tcw8r8j4kGNPB0l4gVfIMbg3xSKAOxDQBDFU9k24Q2hwMxjAdamYWYL5sww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eVTRBtHDJHBSfYlpbLlK9gIIMdsvyZjAE52Bl2e6pUGBz/AQykMIF0yXa5cozVWP22+I0QShIu6yCKD5eeLCVHHftERryiV78oQ+LhEmYq4Po6XON8jOI9f2z/kmDdFSI5rXtxJvwV8MK1MG7rTRYAgGnsVpemGlf5Rg0n8vQteqjgI/QmQCf/R+Slw+Hl72WCRy5r1WL9KFe+dl7QXIw+9+jX84T0xaK7k6q0vheS9bBcO6MRO5gqjBPOP+bvXX4ZXFArudj9/lABhn3/6e5ntki6t0/2ofzjwLzHmVaAsP6hNxsxjndQIdOn6CXT6UCAtTa3dAL6cnXAq4TazOjw==
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Fri, 07 Nov 2025 18:44:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-11-07 13:17, Grygorii Strashko wrote:
From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

Xen uses below pattern for raw_x_guest() functions:

define raw_copy_to_guest(dst, src, len)        \
     (is_hvm_vcpu(current) ?                     \
      copy_to_user_hvm((dst), (src), (len)) :    \
      copy_to_guest_pv(dst, src, len))

This pattern works depending on CONFIG_PV/CONFIG_HVM as:
- PV=y and HVM=y
   Proper guest access function is selected depending on domain type.
- PV=y and HVM=n
   Only PV domains are possible. is_hvm_domain/vcpu() will constify to "false"
   and compiler will optimize code and skip HVM specific part.
- PV=n and HVM=y
   Only HVM domains are possible. is_hvm_domain/vcpu() will not be constified.
   No PV specific code will be optimized by compiler.
- PV=n and HVM=n
   No guests should possible. The code will still follow PV path.

Rework raw_x_guest() code to use static inline functions which account for
above PV/HVM possible configurations with main intention to optimize code
for (PV=n and HVM=y) case.

For the case (PV=n and HVM=n) return "len" value indicating a failure (no
guests should be possible in this case, which means no access to guest
memory should ever happen).

Finally build arch/x86/usercopy.c only for PV=y.

The measured (bloat-o-meter) improvement for (PV=n and HVM=y) case is:
   add/remove: 2/9 grow/shrink: 2/90 up/down: 1678/-32560 (-30882)
   Total: Before=1937092, After=1906210, chg -1.59%

[teddy.astie@xxxxxxxxxx: Suggested to use static inline functions vs
macro combinations]
Suggested-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>

Thanks,
Jason



 


Rackspace

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