From patchwork Thu Aug 13 06:49:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 247670 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp1027242ilo; Wed, 12 Aug 2020 23:51:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNa964jT09IB9VMNfISXv9DYHrOkMkxkj8YSWRG1ybtqwYkoPmoHqFGtbq83ibKCoiQh/n X-Received: by 2002:a25:828a:: with SMTP id r10mr4589740ybk.180.1597301463885; Wed, 12 Aug 2020 23:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597301463; cv=none; d=google.com; s=arc-20160816; b=idEIK3FlRHaz6Azo5SCA4CthPEobzPbe6MFmcqCsnfn5WUBXCfhX1ducpJPVMIamXc iLGz9xn8Q126gMwSYVWYMTq3HXXkKerer7k+NFWaHhTX1WqHuKDijxESVs+5vx0RZwAT 0//8NbmMaeuC/sWs60lfHR/dxPSiZSIm7eVib5niYT6KK5/aRdvEVvDhzbv0a7yZ2bSC cHFrnf25igb2VcH1eeAzZztwSylhn5M+hH79NwBfOvo8Q/hbj5csMq+VCyYRnCy5vEQ2 oUxXriMK5/GdBD3YFRYQELscRL3RmSUqnyTTcwCUqewt/akok00NIGB2Tcvm+PrqxrZA UeXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=JiEkVxcOfuMktQAh35q+WwnwzNzBhoyR5assqUVwYxs=; b=YzVhknbUdw6MJ64+O6jYB1ec+kf+xL8uWJD2TKQCn9ZULLocjQc/yvB46fmWVMgfgG B/3O9fAJXISQl5Fq4jfbXc1pCoWIIG1pu2OMh/A56KdyBkoRHoNpJsJETn3FeUUjPwiC hHsOtx8jcR465ihHVthcEGuh8B/CYjrnmNT/hjUb1fhSN1w5SLxWzBDqijd+ITQd0HXy Oxp5RUuoRDXdkLDs/J7kfniPdwzzbYZnA0jOxOjGPl3wPKW/MN52k9SVMCrT32JwKqEw 9Dht8T+A9/KuyyR/c7wmLUjV9NKlsM44B92qZChR7eJJnKVjpVs0vri6G7c/0LPwPnbr ntBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l8si4016186ybo.264.2020.08.12.23.51.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 23:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:45014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k674p-0006Qr-9f for patch@linaro.org; Thu, 13 Aug 2020 02:51:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673O-0006Pr-KX for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:34 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:44567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673J-0004bn-Ca for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:34 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M9nAB-1k0uW31P77-005sHP; Thu, 13 Aug 2020 08:49:26 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 02/14] linux-user: Validate mmap/mprotect prot value Date: Thu, 13 Aug 2020 08:49:11 +0200 Message-Id: <20200813064923.263565-3-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:MRhH9J+P0CRWlAUTnys0givSaKEFDyAyISPI6Zx2JQHH/E8TC7A fpxBjntVvoxiS1cDgGL9+QI0A+Gvf/NfcBKch3cr5WlKAvPCF8TaF/VPkmoA4r3OC+4GRlS UDIFF5CpS2dhREiYDEn+r7T0gF8C4pHoW63LnNU2jlWD5KAGZykPBPZOpJdV6WCuFWUh1ap NYu+DX3Lr/fB/d5BGFWrg== X-UI-Out-Filterresults: notjunk:1; V03:K0:MnqWGUJFlaI=:V8FUSsWsAEedoemTbEGtrD Fa4Tc6Kh0HdtdfECUniVuedjNaN7nUHuCWkJC3mj/RsGZAMpIlq4NPJ/buAmNnHitGjRkuX9p 36ArzZKNhYc1FiMfmIUD7OBEjDeYMAFp6bTzDvA4mgrgn6ptkjqZbo3xj3Ud+KiLJEGVF8+3X bzli3oHOlAjMeBUPVGLjRw1kfKp07QGiuleAgj9IobYDyL/J6E5sfqwcQyJycuod5wPj6JKKm IfMTOJ7PS3uSZjDxVlvt/BygBeH30FU54tXfxPD+H8fh4Q1eNZA3iBIg1aNfD7f62Eri0yQMg 6XO+ZDxv1PmJoatR50Wg0ZRgIszQwNLsKczAJzm1hQwqsLsEEO5+ZIZ1JMFw8nH/9bGSVS5w+ P7gYQeKtA2eIWHepsZZ8eU8/JoVX+3mqM5A2ny/nxFiZGsze347IofQI/YlIyxNkasZ0a97Ic XKeOtEN4C9L9uwA3PGsu/xrym44T2fSzw1zyxuM0SfBHgDieIS/LYAy/MUGidyfUe8p9ww4x6 t4YiK76p3Nl5xEMW/l3xJ7O2VkH6HVCCNzYznCvX+PQxj3ZGSmVSUD/QKvHX+iqNOfB6JlSpy AqKg5UA0qlwOpo6+O4jKUY8WX49OrIIEJA3HoUKJhYq/XxwSmA6pdXy8/DJqK2dnxlGjs+3sy h6Opq2R8LldBXzHepzN4sS65j97FPLDckCrHw6l+p0/gCcFCwlGhKoAMCWmBLGG9HE9Nkl4vP 8wNOVac5lfvKuZR2xfAiagXxCjfHDV/bOKHjPSl6hgpm30bRHo8p3J7lb/Xc6N65Wj6EwLigx SVTu9fGH/f7xCBf4kIz11YKtf3oH6nPKj6xAdgFtt45sRccIgIeoNDEL0HQgoXr/ZmaARZX Received-SPF: none client-ip=217.72.192.75; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The kernel will return -EINVAL for bits set in the prot argument that are unknown or invalid. Previously we were simply cropping out the bits that we care about. Introduce validate_prot_to_pageflags to perform this check in a single place between the two syscalls. Differentiate between the target and host versions of prot. Compute the qemu internal page_flags value at the same time. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 106 +++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 33 deletions(-) -- 2.26.2 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 0019447892e0..46c7eeba9bd2 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -59,64 +59,96 @@ void mmap_fork_end(int child) pthread_mutex_unlock(&mmap_mutex); } +/* + * Validate target prot bitmask. + * Return the prot bitmask for the host in *HOST_PROT. + * Return 0 if the target prot bitmask is invalid, otherwise + * the internal qemu page_flags (which will include PAGE_VALID). + */ +static int validate_prot_to_pageflags(int *host_prot, int prot) +{ + int valid = PROT_READ | PROT_WRITE | PROT_EXEC | TARGET_PROT_SEM; + int page_flags = (prot & PAGE_BITS) | PAGE_VALID; + + /* + * For the host, we need not pass anything except read/write/exec. + * While PROT_SEM is allowed by all hosts, it is also ignored, so + * don't bother transforming guest bit to host bit. Any other + * target-specific prot bits will not be understood by the host + * and will need to be encoded into page_flags for qemu emulation. + */ + *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + + return prot & ~valid ? 0 : page_flags; +} + /* NOTE: all the constants are the HOST ones, but addresses are target. */ -int target_mprotect(abi_ulong start, abi_ulong len, int prot) +int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { abi_ulong end, host_start, host_end, addr; - int prot1, ret; + int prot1, ret, page_flags, host_prot; - trace_target_mprotect(start, len, prot); + trace_target_mprotect(start, len, target_prot); - if ((start & ~TARGET_PAGE_MASK) != 0) + if ((start & ~TARGET_PAGE_MASK) != 0) { return -TARGET_EINVAL; + } + page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + return -TARGET_EINVAL; + } len = TARGET_PAGE_ALIGN(len); end = start + len; if (!guest_range_valid(start, len)) { return -TARGET_ENOMEM; } - prot &= PROT_READ | PROT_WRITE | PROT_EXEC; - if (len == 0) + if (len == 0) { return 0; + } mmap_lock(); host_start = start & qemu_host_page_mask; host_end = HOST_PAGE_ALIGN(end); if (start > host_start) { /* handle host page containing start */ - prot1 = prot; - for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { + prot1 = host_prot; + for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } if (host_end == host_start + qemu_host_page_size) { - for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { + for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } end = host_end; } - ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret != 0) + ret = mprotect(g2h(host_start), qemu_host_page_size, + prot1 & PAGE_BITS); + if (ret != 0) { goto error; + } host_start += qemu_host_page_size; } if (end < host_end) { - prot1 = prot; - for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { + prot1 = host_prot; + for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } - ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size, - prot1 & PAGE_BITS); - if (ret != 0) + ret = mprotect(g2h(host_end - qemu_host_page_size), + qemu_host_page_size, prot1 & PAGE_BITS); + if (ret != 0) { goto error; + } host_end -= qemu_host_page_size; } /* handle the pages in the middle */ if (host_start < host_end) { - ret = mprotect(g2h(host_start), host_end - host_start, prot); - if (ret != 0) + ret = mprotect(g2h(host_start), host_end - host_start, host_prot); + if (ret != 0) { goto error; + } } - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); mmap_unlock(); return 0; error: @@ -360,19 +392,26 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } /* NOTE: all the constants are the HOST ones */ -abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, +abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, abi_ulong offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len; + int page_flags, host_prot; mmap_lock(); - trace_target_mmap(start, len, prot, flags, fd, offset); + trace_target_mmap(start, len, target_prot, flags, fd, offset); if (!len) { errno = EINVAL; goto fail; } + page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + errno = EINVAL; + goto fail; + } + /* Also check for overflows... */ len = TARGET_PAGE_ALIGN(len); if (!len) { @@ -438,14 +477,15 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* Note: we prefer to control the mapping address. It is especially important if qemu_host_page_size > qemu_real_host_page_size */ - p = mmap(g2h(start), host_len, prot, + p = mmap(g2h(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { goto fail; + } /* update start so that it points to the file position at 'offset' */ host_start = (unsigned long)p; if (!(flags & MAP_ANONYMOUS)) { - p = mmap(g2h(start), len, prot, + p = mmap(g2h(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); if (p == MAP_FAILED) { munmap(g2h(start), host_len); @@ -479,19 +519,19 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & MAP_TYPE) == MAP_SHARED && - (prot & PROT_WRITE)) { + (host_prot & PROT_WRITE)) { errno = EINVAL; goto fail; } - retaddr = target_mmap(start, len, prot | PROT_WRITE, + retaddr = target_mmap(start, len, target_prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) goto fail; if (pread(fd, g2h(start), len, offset) == -1) goto fail; - if (!(prot & PROT_WRITE)) { - ret = target_mprotect(start, len, prot); + if (!(host_prot & PROT_WRITE)) { + ret = target_mprotect(start, len, target_prot); assert(ret == 0); } goto the_end; @@ -502,13 +542,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (real_end == real_start + qemu_host_page_size) { /* one single host page */ ret = mmap_frag(real_start, start, end, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret == -1) goto fail; goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret == -1) goto fail; real_start += qemu_host_page_size; @@ -517,7 +557,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (end < real_end) { ret = mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, end, - prot, flags, fd, + host_prot, flags, fd, offset + real_end - qemu_host_page_size - start); if (ret == -1) goto fail; @@ -533,13 +573,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, else offset1 = offset + real_start - start; p = mmap(g2h(real_start), real_end - real_start, - prot, flags, fd, offset1); + host_prot, flags, fd, offset1); if (p == MAP_FAILED) goto fail; } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); the_end: trace_target_mmap_complete(start); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { From patchwork Thu Aug 13 06:49:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 247671 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp1027497ilo; Wed, 12 Aug 2020 23:51:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze2rEHuXj0SbWpvY5v6U+kBFLpC8CIWQoFI+PTASRrPSDGhTXQsriEuxU3imZjcMd8QUx1 X-Received: by 2002:a25:6f85:: with SMTP id k127mr4379998ybc.12.1597301498974; Wed, 12 Aug 2020 23:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597301498; cv=none; d=google.com; s=arc-20160816; b=x/X1wM46yDgtNVOFP+vX337jaQPrxnCZ2s3f7cRC9ShgCFJDCHo/nuITkyXQ/3Wt1F ZLqYXhKGZBXSsk5Uu9vtFf+3IZT0SNcMe/BpDT/Q6Xs3YOLJQJLcjI3DRrzQR6WCG6yi ZI0Io1ePpcxhy85pdE/x5mzJxUjZDGKDkcOIRVCflQMQOUpEBO6VfU/MgMPRO0l/WFXU lumj3m9j6ErrmFGS58hybKEHlnMGX0ViwLS8IvUrLiVtNUo/zdcObrtSUJKM/yHnluR8 C4w6/jsHtgzG7fCeMQtaOZKam4NKVBcr423u0/LNWUw7H9DvuBG/d/Jk8Yq42/GYZ2ys cAAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=wur1SFGp5xDijZMn7bJkUj1KQAmzkSNHK88wQEnF7jk=; b=Oiv1OhGS8Y4SJCM8nTNv8iJEtlMgCpBiqALdjivu6FKpd3DlVbcDpGPzvJdoNIpVq3 96UG+BvTMwN0DRETRii06t9CyFJDb23+BsJruQ9xCgkJ4HsYLYiDUa3/Eve9oK0jtQ0X rtuq1MtHZVhkvXk3N0k1+qPfcWdvlnLtzNFkbhNHYRZs7O0FYJiuV0nI0H+YQAKuklN6 2XkA0uzbRWDVTfIpUt5iMchM4LqknGgRBGAHUEDmRpsCxqyR4Ak8tdKC0eoGTfwVoRer ZN+UdKk9s015FejKqO2zBTledXUigaf139qiLHdeN2PlLns0m6gfczIwa3VCPIhoKYS2 CvLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p9si4578400ybk.304.2020.08.12.23.51.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 23:51:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k675O-0000DR-Fu for patch@linaro.org; Thu, 13 Aug 2020 02:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673Q-0006Qf-AF for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:36 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:40691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673K-0004bz-88 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:35 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MxEcg-1kuWsR03WC-00xYAE; Thu, 13 Aug 2020 08:49:27 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 03/14] linux-user: Adjust guest page protection for the host Date: Thu, 13 Aug 2020 08:49:12 +0200 Message-Id: <20200813064923.263565-4-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:dak7xG3V4W0QKLOhjASDpYW82SzC8Qlh7wh9zzOo5iPO3aBNtV9 Eqv/0+1EkMSD5+veXfO3ss+U+l4Nz2TXYnZY5zQEOaH/TgW47imod9zFmFtGsdQKXYqZH95 ZWZWZFLtkwR0Qpp/o6M0Nh0igovvtZIee8LmM0IwU0kXVcyPSwuATr/kzczqDyUN/j6YCI7 EtsTVsb/2Qfb0pQhcIqtw== X-UI-Out-Filterresults: notjunk:1; V03:K0:kFJa+kebwxI=:v3fkdMtEbWQdwcCMXgFwyP xaRgl9UMaOeqC3P+k5g5zEzixWLIL5AB1lk4R1FcVEv8F8yf3zv+vDkbzJnTXfaCvz1BGzT6i UGUN4UeW8h1itVEavw7RPrNmKTfZ1BGTRe51F1wxENbUHKSBZwyfKmMBjKMUAjT2WOe1At34c sEF8U+SNdfZDE/gtPvaXhA8D5crwo3N1YY5zyIx1KvQhsg8Eh9JbwQav1VsAbPMBIvn6GluBV ujyY9XlGgg6LR9XyzOrXhJsHbG+VRVVARxHYM1sIjl8q/Re7B3J0aq9GlcHxMbYoDKUqpOrf1 UGzM5/7QkPB4N6PWWzWEEoRcWRv5Y7hWEJxIeQnd3fegDkejPbsvOBnfdqv453xISFuhezNdh dAcWOCoMa71IfrRYEUPIe+KhlLkxewg3UUeCz9JbSQlRh75y3jLXnoY0tulIMaTfX5wCJADN/ LF3TcEl56g4ISmK8zbubnFQspU3yiX3T6k/cCZecRFHs8Lr2J2vp0NupRfLXb7fyJwPh2ZqSM 2LVtxHOVJ0JOKa4eGc0Y47eHLo8BHJ8hWXmXEx39owRoQr+u1KKrojcb7BBkElSNGNdA9L1oI cI6ttAzccfmTiXBsC+Q6swBDQwKkywg+abtFXUnO2RMtYqweRpKcqu61EpOceaeoGsroLU/OI De9ERNLEGTmWtvvnl3SnUIiwi1b2Fbi5IL1DC5+rnAbCmOIq6pw4QsvgFMYjuC6zXVKUlYNdc ZXD7Pzjs45x8KTOdtqMAUo3Gx8SjYLdqdNVesmlEFxaVfg4S/4OEFZQP2ebzxC34iSbUfT2y9 a71RPCsG0QPIzCngMeqCSsKxmhEytN5LoiJpkCV1SNWHBR6ASs8sRWAq++GLYId5zqa342v Received-SPF: none client-ip=217.72.192.75; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Executable guest pages are never directly executed by the host, but do need to be readable for translation. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 46c7eeba9bd2..f2615634201d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -76,8 +76,12 @@ static int validate_prot_to_pageflags(int *host_prot, int prot) * don't bother transforming guest bit to host bit. Any other * target-specific prot bits will not be understood by the host * and will need to be encoded into page_flags for qemu emulation. + * + * Pages that are executable by the guest will never be executed + * by the host, but the host will need to be able to read them. */ - *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + *host_prot = (prot & (PROT_READ | PROT_WRITE)) + | (prot & PROT_EXEC ? PROT_READ : 0); return prot & ~valid ? 0 : page_flags; } From patchwork Thu Aug 13 06:49:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34991C433E1 for ; Thu, 13 Aug 2020 06:54:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08C6720771 for ; Thu, 13 Aug 2020 06:54:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08C6720771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k678U-0005Ev-2K for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:54:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673S-0006SD-9L for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:38 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:51863) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673M-0004cI-E2 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:37 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MtObA-1kyMdC2Fhu-00un0u; Thu, 13 Aug 2020 08:49:28 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 06/14] linux-user: Add support for a group of btrfs ioctls used for subvolumes Date: Thu, 13 Aug 2020 08:49:15 +0200 Message-Id: <20200813064923.263565-7-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:KoC6zAaNCDMyXjDVi2VRR7G7Yd+aqOjsoINDfQuuw6DPQPHqI/e tTW8xJl7DPuWE6e6ToolarjaW76ni4/dVsDYtAfrY3U8ez2Fp0gWLwmMkhR65yIgQ4aXBen SFz5LNsOAr+he5Pj0aKgHr6YreKiHwZoR8j5+kq7CnA5L1/wbpPYF4DtahK9IOBhITpY+78 8OdIxCwJBmsdnJxSN9fCA== X-UI-Out-Filterresults: notjunk:1; V03:K0:oD/jXqUHFa0=:OjeV3eFivXww8CvuFfW+62 T8IAtpesxJm2hSmRI0cNB8JdsSX+gWCGEp6TZ05JRD9zOdAdw/GIq5nLmynmRjjp+vppNbk3B zAxtwemiHLK7Diwp4/ObdX7LjbVtZ8Pnh5COnX3uy4LYyM2OK0WvvveCe0ahQAmJCYG8E1pSC FAA6HZNS4nx2389EdVv5hrE/XdL49qYGY314OLD2l7Jj0gVNHYC+ieh0lwye0Uw4FzvL+chuc 25GLOXGFoceb3GsXBpnI2hefWOjG0QSnbwujcgSDbjmwOj3pruLZ+aQSTpJ2mUDpIBzdp/MBM CZTAvfm+x1ZF3PjK8fGmRDwtJ3BmeoO+X1p/4O26j18XiYp3Ar+PWbH/C5lubLRs1mOXA8O7A WVtZKfeMyFndfOMIwd2Jl1kK7sFitGiPQVqfe3cXMNMtZ3AwHq0SGKBYUHa8TpqmOJFxagSCd H9RoizKxEZf8dMjyTUs7AH0txxcfH/KyZzUeh83AMhvPj/eL4YBVMDexwRtwalbWQUPJlJupg D0by+YJWbXzE5bP4RfcunMlmF5eb9KCWzilgPgS7Hg8lDgl4VxQQs5oOwAMj39EoF0iBIJtIA D2kwRDyiBAp1RxyvM3Mc+1ZvLlg1PSnHX38G7eDfyCX1n90iFvrIh3zCicdgziBl9PyJkvX6m UyulwE6AktzXFUwxcGT85fiFIKumFmpO9Tp+F5/dpKiXcYvaJ1QsywsG0n/azccZ7cdsAA+7d uE8HOlPlxOEffBWmgsKqHpFKs0T6L+2tDRmltKBBRm31so3cCIfoTR8G9l8vUUpZKBIcFzcZA U9PSlx5tw1mYZ/ZpdQIW9X9Ax7gJuzyEphu1tfo9bR87sWeKwHmt6T2g6SC2+F4c6fKnUEL Received-SPF: none client-ip=212.227.17.10; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality of following ioctls: BTRFS_IOC_SUBVOL_CREATE - Creating a btrfs subvolume Create a btrfs subvolume. The subvolume is created using the ioctl's third argument which represents a pointer to a following structure type: struct btrfs_ioctl_vol_args { __s64 fd; char name[BTRFS_PATH_NAME_MAX + 1]; }; Before calling this ioctl, the fields of this structure should be filled with aproppriate values. The fd field represents the file descriptor value of the subvolume and the name field represents the subvolume path. BTRFS_IOC_SUBVOL_GETFLAGS - Getting subvolume flags Read the flags of the btrfs subvolume. The flags are read using the ioctl's third argument that is a pointer of __u64 (unsigned long). The third argument represents a bit mask that can be composed of following values: BTRFS_SUBVOL_RDONLY (1ULL << 1) BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2) BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3) BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4) BTRFS_IOC_SUBVOL_SETFLAGS - Setting subvolume flags Set the flags of the btrfs subvolume. The flags are set using the ioctl's third argument that is a pointer of __u64 (unsigned long). The third argument represents a bit mask that can be composed of same values as in the case of previous ioctl (BTRFS_IOC_SUBVOL_GETFLAGS). BTRFS_IOC_SUBVOL_GETINFO - Getting subvolume information Read information about the subvolume. The subvolume information is returned in the ioctl's third argument which represents a pointer to a following structure type: struct btrfs_ioctl_get_subvol_info_args { /* Id of this subvolume */ __u64 treeid; /* Name of this subvolume, used to get the real name at mount point */ char name[BTRFS_VOL_NAME_MAX + 1]; /* * Id of the subvolume which contains this subvolume. * Zero for top-level subvolume or a deleted subvolume. */ __u64 parent_id; /* * Inode number of the directory which contains this subvolume. * Zero for top-level subvolume or a deleted subvolume */ __u64 dirid; /* Latest transaction id of this subvolume */ __u64 generation; /* Flags of this subvolume */ __u64 flags; /* UUID of this subvolume */ __u8 uuid[BTRFS_UUID_SIZE]; /* * UUID of the subvolume of which this subvolume is a snapshot. * All zero for a non-snapshot subvolume. */ __u8 parent_uuid[BTRFS_UUID_SIZE]; /* * UUID of the subvolume from which this subvolume was received. * All zero for non-received subvolume. */ __u8 received_uuid[BTRFS_UUID_SIZE]; /* Transaction id indicating when change/create/send/receive happened */ __u64 ctransid; __u64 otransid; __u64 stransid; __u64 rtransid; /* Time corresponding to c/o/s/rtransid */ struct btrfs_ioctl_timespec ctime; struct btrfs_ioctl_timespec otime; struct btrfs_ioctl_timespec stime; struct btrfs_ioctl_timespec rtime; /* Must be zero */ __u64 reserved[8]; }; All of the fields of this structure are filled after the ioctl call. Implementation notes: Ioctls BTRFS_IOC_SUBVOL_CREATE and BTRFS_IOC_SUBVOL_GETINFO have structure types as third arguments. That is the reason why a corresponding definition are added in file 'linux-user/syscall_types.h'. The line '#include ' is added in file 'linux-user/syscall.c' to recognise preprocessor definitions for these ioctls. Since the file "linux/btrfs.h" was added in the kernel version 3.9, it is enwrapped in an #ifdef statement with parameter CONFIG_BTRFS which is defined in 'configure' if the header file is present. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200803094629.21898-2-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- configure | 9 +++++++++ linux-user/ioctls.h | 15 +++++++++++++++ linux-user/syscall.c | 3 +++ linux-user/syscall_defs.h | 8 ++++++++ linux-user/syscall_types.h | 28 ++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/configure b/configure index 2acc4d1465f8..1cba4e0b80fb 100755 --- a/configure +++ b/configure @@ -5079,6 +5079,12 @@ if check_include sys/kcov.h ; then kcov=yes fi +# check for btrfs filesystem support (kernel must be 3.9+) +btrfs=no +if check_include linux/btrfs.h ; then + btrfs=yes +fi + # If we're making warnings fatal, apply this to Sphinx runs as well sphinx_werror="" if test "$werror" = "yes"; then @@ -7330,6 +7336,9 @@ fi if test "$kcov" = "yes" ; then echo "CONFIG_KCOV=y" >> $config_host_mak fi +if test "$btrfs" = "yes" ; then + echo "CONFIG_BTRFS=y" >> $config_host_mak +fi if test "$inotify" = "yes" ; then echo "CONFIG_INOTIFY=y" >> $config_host_mak fi diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 0713ae131162..12d14442249f 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -174,6 +174,21 @@ IOCTL(FS_IOC32_GETVERSION, IOC_R, MK_PTR(TYPE_INT)) IOCTL(FS_IOC32_SETVERSION, IOC_W, MK_PTR(TYPE_INT)) +#ifdef BTRFS_IOC_SUBVOL_CREATE + IOCTL(BTRFS_IOC_SUBVOL_CREATE, IOC_W, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args))) +#endif +#ifdef BTRFS_IOC_SUBVOL_GETFLAGS + IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG)) +#endif +#ifdef BTRFS_IOC_SUBVOL_SETFLAGS + IOCTL(BTRFS_IOC_SUBVOL_SETFLAGS, IOC_W, MK_PTR(TYPE_ULONGLONG)) +#endif +#ifdef BTRFS_IOC_GET_SUBVOL_INFO + IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args))) +#endif + #ifdef CONFIG_USBFS /* USB ioctls */ IOCTL(USBDEVFS_CONTROL, IOC_RW, diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bbb61a59c72f..10dd53bf999b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -115,6 +115,9 @@ #ifdef HAVE_DRM_H #include #endif +#ifdef CONFIG_BTRFS +#include +#endif #include "linux_loop.h" #include "uname.h" diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 427a25f5bce5..5435baea38d9 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -972,6 +972,14 @@ struct target_rtc_pll_info { #define TARGET_FS_IOC32_GETVERSION TARGET_IOR('v', 1, int) #define TARGET_FS_IOC32_SETVERSION TARGET_IOW('v', 2, int) +/* btrfs ioctls */ +#define TARGET_BTRFS_IOC_SUBVOL_CREATE TARGET_IOWU(BTRFS_IOCTL_MAGIC, 14) +#define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS TARGET_IOR(BTRFS_IOCTL_MAGIC, 25,\ + abi_ullong) +#define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\ + abi_ullong) +#define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MAGIC, 60) + /* usb ioctls */ #define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0) #define TARGET_USBDEVFS_BULK TARGET_IOWRU('U', 2) diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 3f1f0334649b..cfd8e1c7eea7 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -354,6 +354,34 @@ STRUCT(blkpg_partition, MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */ MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */ +STRUCT(btrfs_ioctl_vol_args, + TYPE_LONGLONG, /* fd */ + MK_ARRAY(TYPE_CHAR, BTRFS_PATH_NAME_MAX + 1)) /* name */ + +STRUCT(btrfs_ioctl_timespec, + TYPE_ULONGLONG, /* sec */ + TYPE_INT) /* nsec */ + +STRUCT(btrfs_ioctl_get_subvol_info_args, + TYPE_ULONGLONG, /* treeid */ + MK_ARRAY(TYPE_CHAR, BTRFS_VOL_NAME_MAX + 1), + TYPE_ULONGLONG, /* parentid */ + TYPE_ULONGLONG, /* dirid */ + TYPE_ULONGLONG, /* generation */ + TYPE_ULONGLONG, /* flags */ + MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* uuid */ + MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* parent_uuid */ + MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* received_uuid */ + TYPE_ULONGLONG, /* ctransid */ + TYPE_ULONGLONG, /* otransid */ + TYPE_ULONGLONG, /* stransid */ + TYPE_ULONGLONG, /* rtransid */ + MK_STRUCT(STRUCT_btrfs_ioctl_timespec), /* ctime */ + MK_STRUCT(STRUCT_btrfs_ioctl_timespec), /* otime */ + MK_STRUCT(STRUCT_btrfs_ioctl_timespec), /* stime */ + MK_STRUCT(STRUCT_btrfs_ioctl_timespec), /* rtime */ + MK_ARRAY(TYPE_ULONGLONG, 8)) /* reserved */ + STRUCT(rtc_time, TYPE_INT, /* tm_sec */ TYPE_INT, /* tm_min */ From patchwork Thu Aug 13 06:49:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 199A1C433E3 for ; Thu, 13 Aug 2020 06:53:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD33420771 for ; Thu, 13 Aug 2020 06:53:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD33420771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k677J-0003Ew-2N for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:53:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673Z-0006Yp-JL for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:45 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:48837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673O-0004cV-9L for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:43 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MUXd0-1kEoCQ0Zqy-00QROc; Thu, 13 Aug 2020 08:49:30 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 09/14] linux-user: Add support for btrfs ioctls used to get/set features Date: Thu, 13 Aug 2020 08:49:18 +0200 Message-Id: <20200813064923.263565-10-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:m6VFafcuoNf5mrYO2G0qw5Y+EVpgAne4v30b/Wd/urDsIc19UKR JASVzk6h6Q1Z+LoSd7rd3nLpaAOJ8rsy8rx9rniFd3DGpirPPfCasJe1izhma1QFIIT0ind hnlAzEBdSmp8DQJcbdmExxBBXlJNUNCUUwxCZiCN4IobW/EuSqZ511jI70NxTLY7R+70kKV +kGcCFllhglI0xKVm5maw== X-UI-Out-Filterresults: notjunk:1; V03:K0:gDbEU3g0TYM=:8YUL5o8Xi1Eh5gEneCwr3f kT2a+gVGT54NTYcgC5QyM6sSOJ6oeIle7Thq27Wf2kOAY5U438TaV198z5s3dnE0GXZlYOL8I 8UUzBgD1OHjs0NqLMB2K84FPuQ9uuLSiybX7iNMytVZqgQiq6LSra6W7FU7X8puLWICng7jd/ McYZDB8gZ3iAVr8NeYRNgfopu8KZxzB3VQgwDqhLRSvaPDeMf0y6FBLhCYPQmJHmrsquIcQe4 eaonlSK4pIBTGxKqLj6wbUZzNOdwQpEAFFva09J2oTl7Br+AADexQ/k4xgzOQeagFqdzIWwb6 YHSLNa9/CI4atSqzrdEzCHp4RQkx4+NkhXN+b2ir/V4iDwheaj+nu5gEhOTLch+qxRkj0D/w2 mqxoNOF/ltWwVs4Fyb5FxBLKky/TnGOAl0QV1ZkEL2pKBrWrgcnEIX0OuhL5CtuHK9RXS0wwd wsnq9C0SXwbt52P7U19I1A1dfouBa+TZFsH8XYjx/eYxxDXRQMhBHa4Hpzb0prwgN9lGhbHL0 JmxuxnhJos/X1fRADnHmI+iASauWvfhglwUqjRenoOpHiO0zW9/3eTTnH4nm5LsoKb9PhvOS6 XB8lmLRJYPvfLUwK+iT54o5GYMOdnNKb/8AdSNkYdUCdClF51EwW7+y++VCKrMCNH9RVcJEkT 3lrrHQVQaJ4565/zZjChGlovbbrZNQbzeywfvgU887oIagwKMeVaCqPwhkvRzcDapbSZ2lZEK zE1Vh/pvSOhBEASNVAb146zEIA6Xv9LNn0Gvl/WhtcYYTZYciHPb1ZYPMp3wBdWWaDSegviU3 N3lXB+rprWHQsZNEiB4oAN8ZrPxwLO0w3VfgpVI1VADy/RqnIBaItz+tennz3Yq0ucgRqKN Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality for following ioctls: BTRFS_IOC_GET_FEATURES - Getting feature flags Read feature flags for a btrfs filesystem. The feature flags are returned inside the ioctl's third argument which represents a pointer to a following structure type: struct btrfs_ioctl_feature_flags { __u64 compat_flags; __u64 compat_ro_flags; __u64 incompat_flags; }; All of the structure field represent bit masks that can be composed of values which can be found on: https://elixir.bootlin.com/linux/latest/source/fs/btrfs/ctree.h#L282 BTRFS_IOC_SET_FEATURES - Setting feature flags Set and clear feature flags for a btrfs filesystem. The feature flags are set using the ioctl's third argument which represents a 'struct btrfs_ioctl_feature_flags[2]' array. The first element of the array represent flags which are to be cleared and the second element of the array represent flags which are to be set. The second element has the priority over the first, which means that if there are matching flags in the elements, they will be set in the filesystem. If the flag values in the third argument aren't correctly set to be composed of the available predefined flag values, errno ENOPERM ("Operation not permitted") is returned. BTRFS_IOC_GET_SUPPORTED_FEATURES - Getting supported feature flags Read supported feature flags for a btrfs filesystem. The supported feature flags are read using the ioctl's third argument which represents a 'struct btrfs_ioctl_feature_flags[3]' array. The first element of this array represents all of the supported flags in the btrfs filesystem. The second element represents flags that can be safely set and third element represent flags that can be safely clearead. Implementation notes: All of the implemented ioctls use 'struct btrfs_ioctl_feature_flags' as third argument. That is the reason why a corresponding defintion was added in file 'linux-user/syscall_types.h'. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200803094629.21898-5-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 12 ++++++++++++ linux-user/syscall_defs.h | 3 +++ linux-user/syscall_types.h | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 55a6cbeca515..50fae1e33bc4 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -216,6 +216,18 @@ IOCTL(BTRFS_IOC_GET_DEV_STATS, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_dev_stats))) #endif +#ifdef BTRFS_IOC_GET_FEATURES + IOCTL(BTRFS_IOC_GET_FEATURES, IOC_R, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags))) +#endif +#ifdef BTRFS_IOC_SET_FEATURES + IOCTL(BTRFS_IOC_SET_FEATURES, IOC_W, + MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 2))) +#endif +#ifdef BTRFS_IOC_GET_SUPPORTED_FEATURES + IOCTL(BTRFS_IOC_GET_SUPPORTED_FEATURES, IOC_R, + MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 3))) +#endif #ifdef BTRFS_IOC_GET_SUBVOL_INFO IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args))) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index f9f94c9c08cc..6cc3c1f6f5ba 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -986,6 +986,9 @@ struct target_rtc_pll_info { abi_ullong) #define TARGET_BTRFS_IOC_DEV_INFO TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30) #define TARGET_BTRFS_IOC_GET_DEV_STATS TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 52) +#define TARGET_BTRFS_IOC_GET_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57) +#define TARGET_BTRFS_IOC_SET_FEATURES TARGET_IOWU(BTRFS_IOCTL_MAGIC, 57) +#define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57) #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MAGIC, 60) /* usb ioctls */ diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 35f94cdfc8ba..808f4daaf72e 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -398,6 +398,11 @@ STRUCT(btrfs_ioctl_get_dev_stats, MK_ARRAY(TYPE_ULONGLONG, 128 - 2 - BTRFS_DEV_STAT_VALUES_MAX)) /* unused */ +STRUCT(btrfs_ioctl_feature_flags, + TYPE_ULONGLONG, /* compat_flags */ + TYPE_ULONGLONG, /* compat_ro_flags */ + TYPE_ULONGLONG) /* incompat_flags */ + STRUCT(rtc_time, TYPE_INT, /* tm_sec */ TYPE_INT, /* tm_min */ From patchwork Thu Aug 13 06:49:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEA23C433E1 for ; Thu, 13 Aug 2020 06:58:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B15E320781 for ; Thu, 13 Aug 2020 06:58:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B15E320781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k67Ba-0002dd-UK for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:58:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673c-0006dH-Hp for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:48 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:45471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673O-0004cX-9W for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:48 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N2VGj-1kpo2f2Rln-013toj; Thu, 13 Aug 2020 08:49:31 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 10/14] linux-user: Add support for a group of btrfs inode ioctls Date: Thu, 13 Aug 2020 08:49:19 +0200 Message-Id: <20200813064923.263565-11-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:M6VZirVnvZvgZh51g8Ztv66mzFUjuxN3G8P0ZyRRhJ0ugJYkCja FfqglNe7ycZDCHZLdD07+72oqsBUW/5MteM0GF3uABb7of1/xJOjv5xWhj/ejRERy9/SEQq tdRnnz9otsrI77fc56Jd419TU64b3N0h04vgiK+rg3MJxkWDpFIOO0LzSm0O/oOE+WXm5ME zUHZssW0rEIA+7Lv8dfjw== X-UI-Out-Filterresults: notjunk:1; V03:K0:L5v3DXt05MY=:7dxhgJ2iRcCeqMhrlqX51X 5jf0tKbPJfkg9cdgGAI282Jh5c872y8RV4i5ozImDUX8Wu+vhWP5BFgv0zy9vEP86d4ZcoCtU IwKu6O5wNjfG2i3SLE04+cX5Z4XHOivHNizPEeYC5YF25/A7SoicFAFVM7jITw/BYBrsu9kL7 L/epPekiTJVVGaiT9Euu6wSu8xpg21rAJ+D0AYdNgkFf3wkeHDnbjtnYXv6QIJY0LKP9pq0Ki 7tLM3EcKoUmznTmiJGmOjYDTSRNSInxYqm/UC6xv8r/5TMhX3p/RYSNeEEQqfbgOhCufz6Mx9 NUNvcIntNdVh5pORcLehf6J5kAPCNE0+U7pn+JgWB5RM78C/8hlaIWOt3bSwtB6pA2L1etEE1 0t1tz+dkbVYj+E3Ir/ZITw8FNl8y31ytb+fx4CyBo/o30NBK5xGrkHeDBQJb461Snr/H/VUa7 IoQUH4M48dzPV4pyiZgzXxUxciVo05xPRYT8CEkLdEJiwUaOf048803FtvR0nARGDaC+zTKAA ybxQITbXkOc8RMlWfxODpl1Ufd6Za/hF+9d5suQGQO013jiqLBoOzo8Sa9RWb4/tzmNrsV73J UP6UgQAVS7Dz9vN7zTZhLdnT4SbkJ90RDkfxovuLbmoSEdbLQFGaH2XrSjqxskP3GA6s7Vcq9 CbOqtuHQaK1mzqprRjV73WjGylunND5SA3ITR1JxIcY9jJouon60w2+75NJ/vTj5nnCnpTdo5 3iXoiCYmxgoFNrOYh7pwdaJncfXVDiBxm5wahNj3owG4dsSehUgRibj7h0inYcPCSVcOZAckS s30vr8nSD+mxM0t2nhH4puGUGocmTCveLFj4xYZW4jeWKow38Q1KWUttSShNOoOIBHd/Lny Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality of following ioctls: BTRFS_IOC_INO_LOOKUP - Reading tree root id and path Read tree root id and path for a given file or directory. The name and tree root id are returned in an ioctl's third argument that represents a pointer to a following type: struct btrfs_ioctl_ino_lookup_args { __u64 treeid; __u64 objectid; char name[BTRFS_INO_LOOKUP_PATH_MAX]; }; Before calling this ioctl, field 'objectid' should be filled with the object id value for which the tree id and path are to be read. Value 'BTRFS_FIRST_FREE_OBJECTID' represents the object id for the first available btrfs object (directory or file). BTRFS_IOC_INO_PATHS - Reading paths to all files Read path to all files with a certain inode number. The paths are returned in the ioctl's third argument which represents a pointer to a following type: struct btrfs_ioctl_ino_path_args { __u64 inum; /* in */ __u64 size; /* in */ __u64 reserved[4]; /* struct btrfs_data_container *fspath; out */ __u64 fspath; /* out */ }; Before calling this ioctl, the 'inum' and 'size' field should be filled with the aproppriate inode number and size of the directory where file paths should be looked for. For now, the paths are returned in an '__u64' (unsigned long long) value 'fspath'. BTRFS_IOC_LOGICAL_INO - Reading inode numbers Read inode numbers for files on a certain logical adress. The inode numbers are returned in the ioctl's third argument which represents a pointer to a following type: struct btrfs_ioctl_logical_ino_args { __u64 logical; /* in */ __u64 size; /* in */ __u64 reserved[3]; /* must be 0 for now */ __u64 flags; /* in, v2 only */ /* struct btrfs_data_container *inodes; out */ __u64 inodes; }; Before calling this ioctl, the 'logical' and 'size' field should be filled with the aproppriate logical adress and size of where the inode numbers of files should be looked for. For now, the inode numbers are returned in an '__u64' (unsigned long long) value 'inodes'. BTRFS_IOC_LOGICAL_INO_V2 - Reading inode numbers Same as the above mentioned ioctl except that it allows passing a flags 'BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET'. BTRFS_IOC_INO_LOOKUP_USER - Reading subvolume name and path Read name and path of a subvolume. The tree root id and path are read in an ioctl's third argument which represents a pointer to a following type: struct btrfs_ioctl_ino_lookup_user_args { /* in, inode number containing the subvolume of 'subvolid' */ __u64 dirid; /* in */ __u64 treeid; /* out, name of the subvolume of 'treeid' */ char name[BTRFS_VOL_NAME_MAX + 1]; /* * out, constructed path from the directory with which the ioctl is * called to dirid */ char path[BTRFS_INO_LOOKUP_USER_PATH_MAX]; }; Before calling this ioctl, the 'dirid' and 'treeid' field should be filled with aproppriate values which represent the inode number of the directory that contains the subvolume and treeid of the subvolume. Implementation notes: All of the ioctls in this patch use structure types as third arguments. That is the reason why aproppriate thunk definitions were added in file 'syscall_types.h'. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200803094629.21898-6-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 20 ++++++++++++++++++++ linux-user/syscall_defs.h | 5 +++++ linux-user/syscall_types.h | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 50fae1e33bc4..169f98f7a301 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -202,6 +202,10 @@ IOCTL(BTRFS_IOC_SNAP_DESTROY, IOC_W, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_vol_args))) #endif +#ifdef BTRFS_IOC_INO_LOOKUP + IOCTL(BTRFS_IOC_INO_LOOKUP, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_args))) +#endif #ifdef BTRFS_IOC_SUBVOL_GETFLAGS IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG)) #endif @@ -212,6 +216,14 @@ IOCTL(BTRFS_IOC_DEV_INFO, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_dev_info_args))) #endif +#ifdef BTRFS_IOC_INO_PATHS + IOCTL(BTRFS_IOC_INO_PATHS, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_path_args))) +#endif +#ifdef BTRFS_IOC_LOGICAL_INO + IOCTL(BTRFS_IOC_LOGICAL_INO, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_logical_ino_args))) +#endif #ifdef BTRFS_IOC_GET_DEV_STATS IOCTL(BTRFS_IOC_GET_DEV_STATS, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_dev_stats))) @@ -228,10 +240,18 @@ IOCTL(BTRFS_IOC_GET_SUPPORTED_FEATURES, IOC_R, MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 3))) #endif +#ifdef BTRFS_IOC_LOGICAL_INO_V2 + IOCTL(BTRFS_IOC_LOGICAL_INO_V2, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_logical_ino_args))) +#endif #ifdef BTRFS_IOC_GET_SUBVOL_INFO IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args))) #endif +#ifdef BTRFS_IOC_INO_LOOKUP_USER + IOCTL(BTRFS_IOC_INO_LOOKUP_USER, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_user_args))) +#endif #ifdef CONFIG_USBFS /* USB ioctls */ diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 6cc3c1f6f5ba..48ebf56d0f36 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -980,16 +980,21 @@ struct target_rtc_pll_info { #define TARGET_BTRFS_IOC_RM_DEV TARGET_IOWU(BTRFS_IOCTL_MAGIC, 11) #define TARGET_BTRFS_IOC_SUBVOL_CREATE TARGET_IOWU(BTRFS_IOCTL_MAGIC, 14) #define TARGET_BTRFS_IOC_SNAP_DESTROY TARGET_IOWU(BTRFS_IOCTL_MAGIC, 15) +#define TARGET_BTRFS_IOC_INO_LOOKUP TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 18) #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS TARGET_IOR(BTRFS_IOCTL_MAGIC, 25,\ abi_ullong) #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\ abi_ullong) #define TARGET_BTRFS_IOC_DEV_INFO TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30) +#define TARGET_BTRFS_IOC_INO_PATHS TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 35) +#define TARGET_BTRFS_IOC_LOGICAL_INO TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 36) #define TARGET_BTRFS_IOC_GET_DEV_STATS TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 52) #define TARGET_BTRFS_IOC_GET_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57) #define TARGET_BTRFS_IOC_SET_FEATURES TARGET_IOWU(BTRFS_IOCTL_MAGIC, 57) #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57) +#define TARGET_BTRFS_IOC_LOGICAL_INO_V2 TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 59) #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MAGIC, 60) +#define TARGET_BTRFS_IOC_INO_LOOKUP_USER TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62) /* usb ioctls */ #define TARGET_USBDEVFS_CONTROL TARGET_IOWRU('U', 0) diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 808f4daaf72e..6e64e6c4f57c 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -382,6 +382,30 @@ STRUCT(btrfs_ioctl_get_subvol_info_args, MK_STRUCT(STRUCT_btrfs_ioctl_timespec), /* rtime */ MK_ARRAY(TYPE_ULONGLONG, 8)) /* reserved */ +STRUCT(btrfs_ioctl_ino_lookup_args, + TYPE_ULONGLONG, /* treeid */ + TYPE_ULONGLONG, /* objectid */ + MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_PATH_MAX)) /* name */ + +STRUCT(btrfs_ioctl_ino_path_args, + TYPE_ULONGLONG, /* inum */ + TYPE_ULONGLONG, /* size */ + MK_ARRAY(TYPE_ULONGLONG, 4), /* reserved */ + TYPE_ULONGLONG) /* fspath */ + +STRUCT(btrfs_ioctl_logical_ino_args, + TYPE_ULONGLONG, /* logical */ + TYPE_ULONGLONG, /* size */ + MK_ARRAY(TYPE_ULONGLONG, 3), /* reserved */ + TYPE_ULONGLONG, /* flags */ + TYPE_ULONGLONG) /* inodes */ + +STRUCT(btrfs_ioctl_ino_lookup_user_args, + TYPE_ULONGLONG, /* dirid */ + TYPE_ULONGLONG, /* treeid */ + MK_ARRAY(TYPE_CHAR, BTRFS_VOL_NAME_MAX + 1), /* name */ + MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_USER_PATH_MAX)) /* path */ + STRUCT(btrfs_ioctl_dev_info_args, TYPE_ULONGLONG, /* devid */ MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* uuid */ From patchwork Thu Aug 13 06:49:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276628 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3A6BC433E1 for ; Thu, 13 Aug 2020 06:57:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BBAA920838 for ; Thu, 13 Aug 2020 06:57:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBAA920838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k67Aq-00015U-27 for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:57:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673b-0006aF-GB for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:47 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:37185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673O-0004ch-95 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:45 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MeTHG-1ke4tT2afM-00aW4U; Thu, 13 Aug 2020 08:49:31 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 11/14] linux-user: Add support for two btrfs ioctls used for subvolume Date: Thu, 13 Aug 2020 08:49:20 +0200 Message-Id: <20200813064923.263565-12-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:YTHbNury7aNAxG8cTwPbNnm4lFterGWtBVcfpph2bCr/7AVKirq /6gK/bd/v5kWNgvlmlZRyiPMbWmSotK3d3KMZJYudz76XPjwXdF2caGC36MiMn6lrwlAGKd cmsQOfXd6b58XFLaTOZz/Z2eNNZpU8lAB/3ITIFIdtVM5Eb8Zkxr55PbV3XMMlk1Xn/tSLR VkutFLW19YPm46WK6q9Wg== X-UI-Out-Filterresults: notjunk:1; V03:K0:WeJMt6sJNpc=:DadDqg5aR0UWP/FZBQ9XZ3 iyEGFiW4LzXhMOVQrs1zF0S2DQFt/AFTi4RMoYN9f8hNukiT9QXHeT1+ehPsiOawV6HFyEStL eu7dd5FfgCiqvMm3/qXzlQRPgwVjR8CWOWlxQz6sASRTL+36CPjyMIdxEH/VdvTR7Je62G4Nm Q3SHizs28uOUDTdLfp4h9uWkgC5OJh1fUhOin41aA3qDuAdySUh2yrYg0nqjGAxkZU1d1hcgh ZBgBuJjg7d518s3zSqRD9nv3b5go8AKpOu6j7AnegcwW4ze1InnBqTSMXZB9cChlBdOzrUaF/ fAXOVuPlAFPmo+2L4DaYijHf1nFgm3D4hsG8JQCwrmm+YxqYxBX6Zv1dXbqKPtKzmk6dEEdVJ iJ58cWtsbEcaWJ5RFInnHHWhyfBaR7Fgu+vwCiBYrR40FCXC7Z0XReIfXgfzKhK+3zTud8TLA wKcBfGkRzIxQbDgTCEMpKaaRJca6gBi05N1ZXGbU7EfLc0k59p57WdWBF6kr6mkFOLhXqRgwO 71sb01DK3hobOoZC0yUADt6Lf0y/7rZ0xpEob992Nih0WjSftBPCPSoa7+xgcmMUORg/Jicjt rN2ajWxHct0GTowN1b/BtV/59qFiLQNv1ge2fa3ii2iGYEVOdCvggkfCENTgWHqeT32MnwNR0 OYBCeeLUaV5X6IAX4s6aM3JjYWn0tYEcrnnUwyIbBg0bhUgy+gurVajaj1TAG5SvAeWtcFqZG kKJS/6uMOZq1yz1eEaaqfixMJfBMZtjIirEaBMonz9DUxkYHHvMBkcjc/sO7UzIIzoaYRp6sf N0ymn59M9TXzQiU7VGJ4C1AJ0bI47MAHNJ4cbYxhoXxezrSvlNYbksUBA4jrH6U0NnBF+b6 Received-SPF: none client-ip=212.227.17.10; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality for following ioctl: BTRFS_IOC_DEFAULT_SUBVOL - Setting a default subvolume Set a default subvolume for a btrfs filesystem. The third ioctl's argument is a '__u64' (unsigned long long) which represents the id of a subvolume that is to be set as the default. BTRFS_IOC_GET_SUBVOL_ROOTREF - Getting tree and directory id of subvolumes Read tree and directory id of subvolumes from a btrfs filesystem. The tree and directory id's are returned in the ioctl's third argument which represents a pointer to a following type: struct btrfs_ioctl_get_subvol_rootref_args { /* in/out, minimum id of rootref's treeid to be searched */ __u64 min_treeid; /* out */ struct { __u64 treeid; __u64 dirid; } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM]; /* out, number of found items */ __u8 num_items; __u8 align[7]; }; Before calling this ioctl, 'min_treeid' field should be filled with value that represent the minimum value for the tree id. Implementation notes: Ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF uses the above mentioned structure type as third argument. That is the reason why a aproppriate thunk structure definition is added in file 'syscall_types.h'. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200803094629.21898-7-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 7 +++++++ linux-user/syscall_defs.h | 3 +++ linux-user/syscall_types.h | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 169f98f7a301..728880b9f37b 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -206,6 +206,9 @@ IOCTL(BTRFS_IOC_INO_LOOKUP, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_args))) #endif +#ifdef BTRFS_IOC_DEFAULT_SUBVOL + IOCTL(BTRFS_IOC_DEFAULT_SUBVOL, IOC_W, MK_PTR(TYPE_ULONGLONG)) +#endif #ifdef BTRFS_IOC_SUBVOL_GETFLAGS IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG)) #endif @@ -248,6 +251,10 @@ IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args))) #endif +#ifdef BTRFS_IOC_GET_SUBVOL_ROOTREF + IOCTL(BTRFS_IOC_GET_SUBVOL_ROOTREF, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_rootref_args))) +#endif #ifdef BTRFS_IOC_INO_LOOKUP_USER IOCTL(BTRFS_IOC_INO_LOOKUP_USER, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_user_args))) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 48ebf56d0f36..b025032626a3 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -981,6 +981,8 @@ struct target_rtc_pll_info { #define TARGET_BTRFS_IOC_SUBVOL_CREATE TARGET_IOWU(BTRFS_IOCTL_MAGIC, 14) #define TARGET_BTRFS_IOC_SNAP_DESTROY TARGET_IOWU(BTRFS_IOCTL_MAGIC, 15) #define TARGET_BTRFS_IOC_INO_LOOKUP TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 18) +#define TARGET_BTRFS_IOC_DEFAULT_SUBVOL TARGET_IOW(BTRFS_IOCTL_MAGIC, 19,\ + abi_ullong) #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGS TARGET_IOR(BTRFS_IOCTL_MAGIC, 25,\ abi_ullong) #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\ @@ -994,6 +996,7 @@ struct target_rtc_pll_info { #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 57) #define TARGET_BTRFS_IOC_LOGICAL_INO_V2 TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 59) #define TARGET_BTRFS_IOC_GET_SUBVOL_INFO TARGET_IORU(BTRFS_IOCTL_MAGIC, 60) +#define TARGET_BTRFS_IOC_GET_SUBVOL_ROOTREF TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 61) #define TARGET_BTRFS_IOC_INO_LOOKUP_USER TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62) /* usb ioctls */ diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 6e64e6c4f57c..851010c78104 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -414,6 +414,17 @@ STRUCT(btrfs_ioctl_dev_info_args, MK_ARRAY(TYPE_ULONGLONG, 379), /* unused */ MK_ARRAY(TYPE_CHAR, BTRFS_DEVICE_PATH_NAME_MAX)) /* path */ +STRUCT(rootref, + TYPE_ULONGLONG, /* treeid */ + TYPE_ULONGLONG) /* dirid */ + +STRUCT(btrfs_ioctl_get_subvol_rootref_args, + TYPE_ULONGLONG, /* min_treeid */ + MK_ARRAY(MK_STRUCT(STRUCT_rootref), + BTRFS_MAX_ROOTREF_BUFFER_NUM), /* rootref */ + TYPE_CHAR, /* num_items */ + MK_ARRAY(TYPE_CHAR, 7)) /* align */ + STRUCT(btrfs_ioctl_get_dev_stats, TYPE_ULONGLONG, /* devid */ TYPE_ULONGLONG, /* nr_items */ From patchwork Thu Aug 13 06:49:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1BF2C433DF for ; Thu, 13 Aug 2020 06:56:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51E1120771 for ; Thu, 13 Aug 2020 06:56:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51E1120771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k679w-0007X7-9M for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:56:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673b-0006aR-IP for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:47 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:36419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673Q-0004cv-1x for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:47 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M734j-1k3fP934D1-008cN3; Thu, 13 Aug 2020 08:49:32 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 13/14] linux-user: Add support for btrfs ioctls used to scrub a filesystem Date: Thu, 13 Aug 2020 08:49:22 +0200 Message-Id: <20200813064923.263565-14-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:sJQgqB+yrFfcywyEc++7ZtyzxLgCyEK7lGk6SAgeNP0VQDgLoDl IiTtMWRyomXxyptlXG9fqYK4VdvQ1ysQWOX1k6U6LmMy53Rz9Ut81BPMdGbUVvX/M/0R1CS bW1TVSjSTeJdBQwkJSROQYn+0ZrzGVh01HRgDdQiVKE/C5ey50rt968aM9p2KqZu1O52DAv Gv0h1y8dhIqOnFE4pRF0g== X-UI-Out-Filterresults: notjunk:1; V03:K0:QIy7UvtZsTQ=:PSAK6HErv2XLCfe0pKgmIR JbgcdkoSODPcULw528N2MNTMCO/VY9n5wlqJ6jDlnAXI2Dt3OCuWdbr0PyqXbkGQ/w7aiNUR4 EmqcuqE3wqtoIvpA6mSkSq/Pg5z3Jyj3e0qbtSD44EtT8JpJa1cVbqpR9rwQ2q9xzNkc8A+Yk USSVd3bJhgYMWpPOxwCM07pBZJTNKYM45/3ThpQv1QPp1OsA9r/OgyrD/KhjRpkAkF+wG231C A1Ix771epWUFvKSRdafPGJU8z2AKFTkvPu4aBa9wy1sbIcnjXU7q+yEdjJJywHg74LjsXl2T7 TzOZcNN1Idt3U0uFkKwZ8Ut+EnucVl32B6pUMkqC0SAq1WN2HGkryd/xTlMwObp4JqDorCq4C yoxZmSw7p1qlnOy+FH8DVCUybJzO4RsjrfuzaCReyDaqXSUhwVQJWBPlEFP6s/WkeeasQmWJ6 4buYQg1gTyBBGYKJcC7fciOtud3Pn0nt9O5crSYw6d8AoYRHjzOJff/AVFVvNMYHNTwsAxtsr 00g03egjOK96wRwtXVG5zEBKWRugaorZ1Fd9v6oxXa3T+vJrUo0cc2LSKYz4/37rIcgjYu2BH cIwcWz3d9WzqXxyArsKJxS0NPgid2Q+fAjXIgXCRWkPTIyD0wjBNi8dbVSL5NVVNdZ+Opg2Af JyvfSrcFPOmjAwyJcjLFDQqGv+IjOR5cMhnIFKDL/YaHrAk5kiKJiK0YYHXECrwUn9qV1UT5+ lBpREzfYnISkkA9rekMTc7N4dBXqnTYRaOUTvKRKeNK07XINHNvsujY1ZuDPHDbiMeA7+eA/W PR5FVM7yIaKeOXvKWw5XaWmAcBHbUXRXmvnwG1EyM29FTRYtisAMXTCkvi1Z4Q5HBh9u6FH Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality for following ioctls: BTRFS_IOC_SCRUB - Starting a btrfs filesystem scrub Start a btrfs filesystem scrub. The third ioctls argument is a pointer to a following type: struct btrfs_ioctl_scrub_args { __u64 devid; /* in */ __u64 start; /* in */ __u64 end; /* in */ __u64 flags; /* in */ struct btrfs_scrub_progress progress; /* out */ /* pad to 1k */ __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8]; }; Before calling this ioctl, field 'devid' should be filled with value that represents the device id of the btrfs filesystem for which the scrub is to be started. BTRFS_IOC_SCRUB_CANCEL - Canceling scrub of a btrfs filesystem Cancel a btrfs filesystem scrub if it is running. The third ioctls argument is ignored. BTRFS_IOC_SCRUB_PROGRESS - Getting status of a running scrub Read the status of a running btrfs filesystem scrub. The third ioctls argument is a pointer to the above mentioned 'struct btrfs_ioctl_scrub_args'. Similarly as with 'BTRFS_IOC_SCRUB', the 'devid' field should be filled with value that represents the id of the btrfs device for which the scrub has started. The status of a running scrub is returned in the field 'progress' which is of type 'struct btrfs_scrub_progress' and its definition can be found at: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L150 Implementation nots: Ioctls in this patch use type 'struct btrfs_ioctl_scrub_args' as their third argument. That is the reason why an aproppriate thunk type definition is added in file 'syscall_types.h'. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200803094629.21898-9-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 11 +++++++++++ linux-user/syscall_defs.h | 3 +++ linux-user/syscall_types.h | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 882bfb3e8854..e3bfe7877433 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -215,6 +215,17 @@ #ifdef BTRFS_IOC_SUBVOL_SETFLAGS IOCTL(BTRFS_IOC_SUBVOL_SETFLAGS, IOC_W, MK_PTR(TYPE_ULONGLONG)) #endif +#ifdef BTRFS_IOC_SCRUB + IOCTL(BTRFS_IOC_SCRUB, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args))) +#endif +#ifdef BTRFS_IOC_SCRUB_CANCEL + IOCTL(BTRFS_IOC_SCRUB_CANCEL, 0, TYPE_NULL) +#endif +#ifdef BTRFS_IOC_SCRUB_PROGRESS + IOCTL(BTRFS_IOC_SCRUB_PROGRESS, IOC_RW, + MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args))) +#endif #ifdef BTRFS_IOC_DEV_INFO IOCTL(BTRFS_IOC_DEV_INFO, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_dev_info_args))) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 8ae54f6946ed..d4fe0085bef4 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -987,6 +987,9 @@ struct target_rtc_pll_info { abi_ullong) #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGS TARGET_IOW(BTRFS_IOCTL_MAGIC, 26,\ abi_ullong) +#define TARGET_BTRFS_IOC_SCRUB TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 27) +#define TARGET_BTRFS_IOC_SCRUB_CANCEL TARGET_IO(BTRFS_IOCTL_MAGIC, 28) +#define TARGET_BTRFS_IOC_SCRUB_PROGRESS TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 29) #define TARGET_BTRFS_IOC_DEV_INFO TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30) #define TARGET_BTRFS_IOC_INO_PATHS TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 35) #define TARGET_BTRFS_IOC_LOGICAL_INO TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 36) diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 51743bb75237..8d4b5b3e921a 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -406,6 +406,33 @@ STRUCT(btrfs_ioctl_ino_lookup_user_args, MK_ARRAY(TYPE_CHAR, BTRFS_VOL_NAME_MAX + 1), /* name */ MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_USER_PATH_MAX)) /* path */ +STRUCT(btrfs_scrub_progress, + TYPE_ULONGLONG, /* data_extents_scrubbed */ + TYPE_ULONGLONG, /* tree_extents_scrubbed */ + TYPE_ULONGLONG, /* data_bytes_scrubbed */ + TYPE_ULONGLONG, /* tree_bytes_scrubbed */ + TYPE_ULONGLONG, /* read_errors */ + TYPE_ULONGLONG, /* csum_errors */ + TYPE_ULONGLONG, /* verify_errors */ + TYPE_ULONGLONG, /* no_csum */ + TYPE_ULONGLONG, /* csum_discards */ + TYPE_ULONGLONG, /* super_errors */ + TYPE_ULONGLONG, /* malloc_errors */ + TYPE_ULONGLONG, /* uncorrectable_errors */ + TYPE_ULONGLONG, /* corrected_er */ + TYPE_ULONGLONG, /* last_physical */ + TYPE_ULONGLONG) /* unverified_errors */ + +STRUCT(btrfs_ioctl_scrub_args, + TYPE_ULONGLONG, /* devid */ + TYPE_ULONGLONG, /* start */ + TYPE_ULONGLONG, /* end */ + TYPE_ULONGLONG, /* flags */ + MK_STRUCT(STRUCT_btrfs_scrub_progress), /* progress */ + MK_ARRAY(TYPE_ULONGLONG, + (1024 - 32 - + sizeof(struct btrfs_scrub_progress)) / 8)) /* unused */ + STRUCT(btrfs_ioctl_dev_info_args, TYPE_ULONGLONG, /* devid */ MK_ARRAY(TYPE_CHAR, BTRFS_UUID_SIZE), /* uuid */ From patchwork Thu Aug 13 06:49:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 276626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93227C433E1 for ; Thu, 13 Aug 2020 06:59:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 687E220781 for ; Thu, 13 Aug 2020 06:59:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 687E220781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k67Cw-0005jr-NG for qemu-devel@archiver.kernel.org; Thu, 13 Aug 2020 02:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673c-0006df-M7 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:48 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:57799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k673Q-0004cu-1L for qemu-devel@nongnu.org; Thu, 13 Aug 2020 02:49:48 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Ma1HG-1k9KY50mNY-00Vxhe; Thu, 13 Aug 2020 08:49:33 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 14/14] linux-user: Fix 'utimensat()' implementation Date: Thu, 13 Aug 2020 08:49:23 +0200 Message-Id: <20200813064923.263565-15-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200813064923.263565-1-laurent@vivier.eu> References: <20200813064923.263565-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Ciq6cPuHeA4AGiSmNqi0J42q6MLfR/IXUMXK4fPs/iZgsmVr6jD lHt0vM0mVHnqPPFpAW7VnaC/vhwza4tlJuKZ2LZsWUgACMeaYqj/LTHKIfq1PiX3aG6IP+E wtWtjU+4HSnogSoAfkPPrWRkJB5PyJRo5yFeeTQmpwRyjwzAaeOFAtQEunUOvxPN9SjMGL3 FtcAn1fPtZZOcSFiQbkVw== X-UI-Out-Filterresults: notjunk:1; V03:K0:zmZxLy57UYI=:qhlGyJnwzJXAYhd1gjj4XG DmsnhoLOjF0XrC8hxDMt3FPbHDPAVzFV8SjXra3Vd/Gkj0dXv0fhRLU/AKld9xSFrLVZlqWFn YKHCKVlZ8Kqkmx5Zcy6k7SFRm6qIRQRCVmQfsSwOy9CdQY1Zk7lncgiFP6BD1siDdeAEJRKu9 cjHqDJ3oLIIlRqLDmxmIqyUghsnTu3dE2fMAKmxz2r0+H5WBLi73ctoCHjeUWvcl37+d2jo8Z rlUDV75LjRluRsM71wbd3ql3sraTcQ3wAQe9e6g/KP8Wjtix+ZxjqQhV2SHoGDWoblcXMxOXv PMuB9ncnheKaql6Klc9Q7k0cyXSKr92+RoXty6+Klt1cxZaVcC5EgFW5LlZl0w5noRo5YHOdj zRL/jD5JUIiqw3FSVbooXJPZtCklbBLS9yvjqT6axWu0//tAO9++DnmTPG9Mt+gTzkjkVemiZ cdABxDbVsV6sAaY3MSD55fdGTAslyjsbbCZQx6bdk1ls/LK8KXQ55YksJ29d05JK1pC+q4DFi AL7OKTJdffab36ANLb4MjvIxNC8V4/l8//4kgF8iEd+uewoVeA/6vSN+kODP4psDQiUcgQdmI ItX7dGHVxuheS9EXA/U/b8PwoFhGzRz9LdOm3pTiuXeXw909ONbgowOWez7EjcJA4rt1FIIsK qi+4j7KoFK46hIaX/bXhfixUA9l89GuGMix94rRt8ufCgLacogulczI6IDfE9lGCrXz+T6QYi O0aS9tu5/6ee9A2WoHye/wWXWMvySBn9IWv5+iBIaBSM4U9TFwtv2qNylkZtu6xwCvz61DiGr dovxunUbo0xAXGO/5kaniEpTrB8ny6zyRDQNRpiN05HQoP7rWdZBPddwR/iRp1by2obZUSB Received-SPF: none client-ip=212.227.17.10; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:49:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta Implementation of syscall 'utimensat()' in 'syscall.c' uses functions target_to_host/host_to_target_timespec() to convert values of 'struct timespec' between host and target. However, the implementation doesn't check whether the conversion succeeds and thus can cause an inappropriate error or succeed unappropriately instead of setting errno EFAULT ('Bad address') which is supposed to be set in these cases. This was confirmed with the LTP test for utimensat ('testcases/utimensat') which fails for test cases when the errno EFAULT is expected. After changes from this patch, the test passes for all test cases. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200811113101.6636-1-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 10dd53bf999b..96ae942909ab 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11922,8 +11922,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, if (!arg3) { tsp = NULL; } else { - target_to_host_timespec(ts, arg3); - target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); + if (target_to_host_timespec(ts, arg3)) { + return -TARGET_EFAULT; + } + if (target_to_host_timespec(ts + 1, arg3 + + sizeof(struct target_timespec))) { + return -TARGET_EFAULT; + } tsp = ts; } if (!arg2)