From patchwork Tue Nov 21 22:10:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13463689 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 AE509C61D85 for ; Tue, 21 Nov 2023 22:11:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.638306.994763 (Exim 4.92) (envelope-from ) id 1r5YxH-0007jF-Rl; Tue, 21 Nov 2023 22:10:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 638306.994763; Tue, 21 Nov 2023 22:10:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5YxH-0007j2-NG; Tue, 21 Nov 2023 22:10:51 +0000 Received: by outflank-mailman (input) for mailman id 638306; Tue, 21 Nov 2023 22:10:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5YxG-0006PS-Qg for xen-devel@lists.xenproject.org; Tue, 21 Nov 2023 22:10:50 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d37d086d-88ba-11ee-98e1-6d05b1d4d9a1; Tue, 21 Nov 2023 23:10:49 +0100 (CET) Received: from pps.filterd (m0174679.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ALJcd1C031085; Tue, 21 Nov 2023 22:10:34 GMT Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2233.outbound.protection.outlook.com [104.47.51.233]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3uh0hhgrv3-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 22:10:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB8836.eurprd03.prod.outlook.com (2603:10a6:10:40c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Tue, 21 Nov 2023 22:10:28 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::8e03:368:1fd7:1822]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::8e03:368:1fd7:1822%6]) with mapi id 15.20.7002.028; Tue, 21 Nov 2023 22:10:28 +0000 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" X-Inumbo-ID: d37d086d-88ba-11ee-98e1-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+oTrug03bO6QMDVE2fZb4n6QkQkiYtc7LUvlIWe6QIW4Q7Morj3kHkdflWv/WRoC1fRSGUeA6PmLyZfchw7sjECTyimw/dfx6eKOoA5mzG8BkJNRSeZXgAyj9dzBs8RKpj66iuzVN0tvs9T5y9xXG23STbeWXmNva+pQp6QW48H1EUC0GD4HGzdYceEJcZcTDDG0mtR4zDPFidDk3ud7LhoFkoazm+hu/4aviKZmly9MXqa/bBdLOAUMJtUxSHLO4Uae8gH8DjjmLmB2nCkdgaRITi5lHcfq1i6pW719RLUU+u2dhXy4xzYBeLATprh64ELMG3V8JRyhdCnVnEk9Q== 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=ffYRx7XuJDukcGSWHJ7JKVQ+d8C2usuIHgJipHrngZ4=; b=YEtTuGWyIcbvsJ9f0YRazOenepm2HF8GQmFy2d59F/JiyCY8ccDv33vq20lJeSO33rh/rctmuioIrLl+v1Hrvh/yzP4OE3ePJdbo6YHAzRrcCiyuvA2Jh1I06Q3LEzbPLtgPEK0bvV+6ybT+intalSzDibrETMKfcH+tKWOBb7mAUIzrOmDxt3SrhQD83Ixz2LfKIjWJlAnLz/Aunkxq0qKtl6GIoX0zoYCQ3kh/6rDNHJPJvzMtvKSAluodt2fMqdQRSVPK9PZStWDNydhSUFSiXyS+/Ug4CodR9+fKOjj0fzbsRzjfz3BIo7/JAm5cthFyTQPF56QkzUK6JMDmww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ffYRx7XuJDukcGSWHJ7JKVQ+d8C2usuIHgJipHrngZ4=; b=gKASjAqHwMmv0ZXPeRtLBFyp5DC6FQBknfHiNZKoUIzQGWyYnRZa+Pw8YED71UM16CzEY8g9wB4boMhDLfAUe+Kp1q76qRoGontVHfbXF5hu1AKCg9U10D8H+lVrkbLfdBikI1ttjAlH8Dq8fuJCFLNt6blp0HoaK8YodQkiqKDtEcl+HirBTAzXdNNINp6MIz5jJMlbrsSyaAm78P+1A6wQK4wTJiZdXdZP2Mjk3kU03B5YAvYFIKi8MPSr6EwxtqvPMXnOO3xC/eXJ72CQq4OKvqGL1oNe+LzCZeOwVsOrtNMyUxmzX78tJZyTgzFLHOMD8EueMqlRYOUdtc1IAw== From: Volodymyr Babchuk To: "qemu-devel@nongnu.org" CC: David Woodhouse , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , David Woodhouse , Paul Durrant , "Michael S. Tsirkin" , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Anthony Perard , "open list:X86 Xen CPUs" Subject: [PATCH v2 3/6] xen: xenstore: add possibility to preserve owner Thread-Topic: [PATCH v2 3/6] xen: xenstore: add possibility to preserve owner Thread-Index: AQHaHMeI3Gf8Xs6dHUOphRyadMs2ow== Date: Tue, 21 Nov 2023 22:10:27 +0000 Message-ID: <20231121221023.419901-4-volodymyr_babchuk@epam.com> References: <20231121221023.419901-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231121221023.419901-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB8836:EE_ x-ms-office365-filtering-correlation-id: 0b5b5819-1eae-4f49-92f7-08dbeadeab95 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 8SyCokp/FW7dJRKCZQZyv9CgiMYc8TV9VtzrtN8Lg9XgIMamyC6+Yo/2/2xKYRziteRPrYXknLhsoU3of6ssWYlw11O98+Ukb+Dp3VUeDCdvyUxCrPk7ExEz5sv4iltZjYkk7zy4Jppr4yIsTJuAAJSQMIWHiOgv+rUD0lTH4JxpqpEnhhvpyYc7o+YTrvmvmNLWunq6CvOlw4Hpi63/525DfKrOhnc+2nVvFbDxaSSd4/ppquOE5XB5VnJxPZ0HmKaInRNk/rnQ8Dc337Q8SstdmG/pyK6DuEA/sb1Q4lKkdUmx5lfIrYEYgJ2ngDhKJAzsN9tullFhUTTmPBl8HiZ6iUKpQnCb6pCa42emnomi7Urni2C9Cyv8MICim91ersiBLCLQDk/fL0sIs590CE066ZlhckoUAe6TxWKwtwQtBToSMT0dQau3Z32/CUfAzjZpseh+9MYIF/UEPODsiktmut00YV1kWKDvGyNZNF0uS9WY3h5w2CNCF+xnYPnM2pPUVZhfd5P2yB7ExLi7ForBB5v1M8jeAru9kDLe3ooYYFr9/IAEUMqegwvM4zIpWuXV26Gvi5S7ZRz2xub8vQ1uT8rG8ykmXzrW14iE64/+NDQbAmDZ96POAGseZaOY x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(136003)(39860400002)(376002)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(41300700001)(86362001)(36756003)(7416002)(5660300002)(2906002)(38070700009)(122000001)(6512007)(2616005)(6506007)(55236004)(6486002)(83380400001)(71200400001)(1076003)(478600001)(26005)(38100700002)(91956017)(66556008)(66446008)(316002)(66946007)(6916009)(64756008)(54906003)(4326008)(8676002)(66476007)(76116006)(8936002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?XUXoy6WLSuy2I/xwBQMOTpl?= =?iso-8859-1?q?QFonOYjE+lTe4Lw0/Hv8WxpzFe3TT8R44l8tBefqDfsdRaCs5rTSTM4Dc21c?= =?iso-8859-1?q?wj5ASiB/PR5CxiWv/JiAIXXX/nHSqQwSXVQPjWttinkA+qEXxrnnEuJ93tG4?= =?iso-8859-1?q?QzCdQFEuotTwq18RkXyT5eLx9IIwLlP0cGIr/zi3FTyFMtUwhMZyK4nzWKcy?= =?iso-8859-1?q?g7VOlXNGw7Dir76/EsLlGF4wMRHJ3wMwb7XZ1dnaSH/SaR3/wgioPRJAC/YF?= =?iso-8859-1?q?dNTfaIHP9e6WElJhDR9KW1/PmmhlhsJjwiB400g3tWYP+zD8TwcYBRfOAglp?= =?iso-8859-1?q?ULWc0pdQbYjHbMb/Cx8YYMpq7AzTqZYhuZGcC+ru2hIY4GH39Z5AtDrnw2jb?= =?iso-8859-1?q?aFTdg3DZISAdRBBOfyX1iRuqDmHcsskmCzDbgq2XmVHVbwpHA/2Mr37W0Gq7?= =?iso-8859-1?q?E93Wtn57XCBiQ/be/e5ZPrCXfkPIENLXFu8REUWgEcKy1YZST/3vN9zGNE1W?= =?iso-8859-1?q?75RC4SoKYATVZtOm6CW8RaJsjDIn1nYVdvqiPJJ17ky/rLNFrMbWP8B3/OEo?= =?iso-8859-1?q?e1dPqfj+F4SAEPSc2ORhsbOCbYz3ERHdmm5/vQu+k/gIukuLvhOXGUSncJHQ?= =?iso-8859-1?q?mC8uFDuJy+Ov2L3UlDHhFSY1rkYWb64rk/USKy1d6MOKlUhtMc7eNcXFh+3F?= =?iso-8859-1?q?7hqK6PBa2xZFZ6MQxCMe/oyvgD8lhdpqHbCiZPTKLgfwXVROgobqkWDfLOXO?= =?iso-8859-1?q?LupC9/LChijyFR4pScCO03bm2CpUwHsFr++mKV1zwhgiUQryankVYeGlXvHk?= =?iso-8859-1?q?Df9hvB3hfUh54IAop4siQ4QF/NKaa8D6YcgjA9dl4gJIu43cJf63IBkTlm+S?= =?iso-8859-1?q?7hJEEnfUJ+9apljErrTIYe2EPPasqNsGti8wffQhGiew6COBmCF6X45GU3Wp?= =?iso-8859-1?q?bSC5NKM42hpkecXckNzGwg+EaM3SpLnA7ZNa4u7YMrHVlb6vhgEXgR/xVCVk?= =?iso-8859-1?q?4ugpEVbc1QDH/99Nl3S32PscN0tzVihujXkWKn1DCqsXO79XaZjA6DX2a2le?= =?iso-8859-1?q?s+ulgHz4Jhnj6RuifNtXbHTgUEcN7aWnGPSeA3weecNoI+GblsjR2GdVObmO?= =?iso-8859-1?q?bGljcAFyWespgR4Qm3+LLX3GhZDqbxUM91b4YEDX7NgL4pYG1uXusYRP5vu0?= =?iso-8859-1?q?O8YvBdkrz4ylrdUG6fJdeGPMthzwZLLMgQ7Fouh26NlHcFKx8Wa+TMgH6dUm?= =?iso-8859-1?q?QunkEgM03IdjxOMMxs93NK8W/V9PUT8ryowi+6qdA7toyu/tCs4/O1bIdUPG?= =?iso-8859-1?q?QD/XHk22gZTU6Kw5aW7p7/MkyDsHQlWB/wuA9Lu9jsqYQOSDTLvI7f3GRXHP?= =?iso-8859-1?q?+Oy9YX14SpawBvhUwJzlPQ69AwMm7Zsi/UGdXAdhN9u7CNJ22JH1sfOunSHt?= =?iso-8859-1?q?RfKveMWr9j9UMYVLz0X6da/ykpOG7VemJlYndRSS8m3naMGQS4GC73AEQ1Gi?= =?iso-8859-1?q?2ee+fzVnxPPV8GdIYNqkR2lyzIHS39ODvQISz3NFFWXLywYyTC+Y5sGVZ5U6?= =?iso-8859-1?q?hsuB0epukWfKr8CTd1skeK/tslRYOzkp/ZzdVP1wqYm4zlxcS0rV17krshRX?= =?iso-8859-1?q?Jcw6T0DZwQLAhWpmXl57h22ug3aNlV0P04T/hiw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b5b5819-1eae-4f49-92f7-08dbeadeab95 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2023 22:10:27.7937 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BEVgIfVgeiTu73ik19OyXyA8m6UD0BdLwEuXVifPPf8sfRMnihbq+VgcI+/RqiL6cWCoOzNPs/RmWKw61WvmxLfgUt0mX+OaSEPZU1zi1ac= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB8836 X-Proofpoint-GUID: W2bYEx-fBJEg5TRa3Y--B4-uviAGyo8_ X-Proofpoint-ORIG-GUID: W2bYEx-fBJEg5TRa3Y--B4-uviAGyo8_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-21_12,2023-11-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 phishscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 spamscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311210173 Add option to preserve owner when creating an entry in Xen Store. This may be needed in cases when Qemu is working as device model in a domain that is Domain-0, e.g. in driver domain. "owner" parameter for qemu_xen_xs_create() function can have special value XS_PRESERVE_OWNER, which will make specific implementation to get original owner of an entry and pass it back to set_permissions() call. Please note, that XenStore inherits permissions, so even if entry is newly created by, it already has the owner set to match owner of entry at previous level. Signed-off-by: Volodymyr Babchuk --- In v2: - Pass transaction to xs_get_permissions() in libxenstore_create() - Added comment before XS_PRESERVE_OWNER defintion - Extended the commit message --- hw/i386/kvm/xen_xenstore.c | 18 ++++++++++++++++++ hw/xen/xen-operations.c | 12 ++++++++++++ include/hw/xen/xen_backend_ops.h | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 6e651960b3..d0fd5d4681 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1595,6 +1595,24 @@ static bool xs_be_create(struct qemu_xs_handle *h, xs_transaction_t t, return false; } + if (owner == XS_PRESERVE_OWNER) { + GList *prev_perms; + char letter; + + err = xs_impl_get_perms(h->impl, 0, t, path, &prev_perms); + if (err) { + errno = err; + return false; + } + + if (sscanf(prev_perms->data, "%c%u", &letter, &owner) != 2) { + errno = EFAULT; + g_list_free_full(prev_perms, g_free); + return false; + } + g_list_free_full(prev_perms, g_free); + } + perms_list = g_list_append(perms_list, xs_perm_as_string(XS_PERM_NONE, owner)); perms_list = g_list_append(perms_list, diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c index e00983ec44..ae8265635f 100644 --- a/hw/xen/xen-operations.c +++ b/hw/xen/xen-operations.c @@ -300,6 +300,18 @@ static bool libxenstore_create(struct qemu_xs_handle *h, xs_transaction_t t, return false; } + if (owner == XS_PRESERVE_OWNER) { + struct xs_permissions *tmp; + unsigned int num; + + tmp = xs_get_permissions(h->xsh, t, path, &num); + if (tmp == NULL) { + return false; + } + perms_list[0].id = tmp[0].id; + free(tmp); + } + return xs_set_permissions(h->xsh, t, path, perms_list, ARRAY_SIZE(perms_list)); } diff --git a/include/hw/xen/xen_backend_ops.h b/include/hw/xen/xen_backend_ops.h index 90cca85f52..79021538a3 100644 --- a/include/hw/xen/xen_backend_ops.h +++ b/include/hw/xen/xen_backend_ops.h @@ -266,6 +266,13 @@ typedef uint32_t xs_transaction_t; #define XS_PERM_READ 0x01 #define XS_PERM_WRITE 0x02 +/* + * This is QEMU-specific special value used only by QEMU wrappers + * around XenStore. It can be passed to qemu_xen_xs_create() to + * inherit owner value from higher-level XS entry. + */ +#define XS_PRESERVE_OWNER 0xFFFE + struct xenstore_backend_ops { struct qemu_xs_handle *(*open)(void); void (*close)(struct qemu_xs_handle *h);