From owner-freebsd-hackers@freebsd.org Fri Apr 26 03:39:04 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7B8B215871C2 for ; Fri, 26 Apr 2019 03:39:04 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2ED4880A1D for ; Fri, 26 Apr 2019 03:39:03 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-lf1-f41.google.com with SMTP id t11so1219729lfl.12 for ; Thu, 25 Apr 2019 20:39:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=cWXcO6Xi6mRZKZofmewST1sa6Rr2B/jXWhnxA7UElH4=; b=qJRf5u4t3Km0ILLubdJr5nJ+tg8a3K+qNRVWaqjK8K+BfdzBTIwdjn7/VNUz9Bcy/a 7sI6DoXv+mFS7Zdu8Lw0PDFa5Kb8YXbLDY1pvD/9O4X1vBf8YpCqRzDGwbxWmsXbdI99 cz3M3hQTdD7ubJE925/jw2bI/eDNhkg5SSK+sRDtx2tZn5lEB80FsxBJknoawku0vjAu IxlzvnPy/i7dMqxt+8eZuuo/Boxx6735/kCEDoQQFfaNAX+nXp1tkntfJD5T8DQNnu7e yB1F5Ot7v8sUM4bX4KiqIMwWUjTO3mjPymXzYBZfFGl3bs4H4MRURwNvHHJ+czY/Uc+t q8QQ== X-Gm-Message-State: APjAAAVsHEMQ6uLIeaOvHIHE9lgYLYbfiwdRVU1bdZz6oet5ZYLITxet yJCkV+4fPSNf46ObY6i2knJH7t94Bw3xnoedA5G7cTG0BME= X-Google-Smtp-Source: APXvYqx9jImepIPEMqhGRuMdCYynbREKSoBOrhEPzY9YDn9jM/5ejr4HkErsTquegzYCcQo/wd2ppu65edFeWlsOn3o= X-Received: by 2002:ac2:51a1:: with SMTP id f1mr14474252lfk.129.1556249506603; Thu, 25 Apr 2019 20:31:46 -0700 (PDT) MIME-Version: 1.0 From: Alan Somers Date: Thu, 25 Apr 2019 21:31:35 -0600 Message-ID: Subject: buf(9) woes: when does bcopy do nothing at all? To: FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 2ED4880A1D X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=asomers@gmail.com X-Spamd-Result: default: False [-3.29 / 15.00]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.94)[-0.936,0]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; MIME_TRACE(0.00)[0:+]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; TO_DOM_EQ_FROM_DOM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; SUBJECT_ENDS_QUESTION(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[41.167.85.209.list.dnswl.org : 127.0.5.0]; IP_SCORE(-1.34)[ip: (-0.51), ipnet: 209.85.128.0/17(-3.88), asn: 15169(-2.25), country: US(-0.06)]; RWL_MAILSPIKE_POSSIBLE(0.00)[41.167.85.209.rep.mailspike.net : 127.0.0.17]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_LAST(0.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 03:39:04 -0000 How is it possible that bcopy() doesn't affect its output array at all? While investigating a data corruption issue in fuse, I narrowed the problem down to a bcopy operation that apparently has no affect. The code in question is: bcopy(cp, iov->iov_base, cnt); r = memcmp(cp, iov->iov_base, cnt); if (r) printf("uiomove: miscompare\n"); Rationally, I would expect that line never to be printed. But it does. The destination is always all zeros, even though the source is not. I can only guess that there's something wrong about the way that I I'm using buf(9), because the output is part of a buffer allocated by bread(9). I've been able to rule out: 1) Race conditions. The bug is 100% reproducible, and doubling the bcopy or changing the timing in other ways has no effect. 2) Unmapped buffer. I verified that the buf is not unmapped_buf. 3) Overlapping src and dst 4) Duplicated pages. I verified that each of the buf's pages has a unique physical address 5) Bad RAM. My machine passes memtest86, and anyway the failure is too specific and reproducible to be caused by bad hardware. What could I be missing? Do I need to do something to prepare the buf before I can use it? The code that allocates the buffer is here: https://svnweb.freebsd.org/base/projects/fuse2/sys/fs/fuse/fuse_io.c?view=markup#l240 -Alan