New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I/O error while formatting card #10
Comments
What is your exact chip version? RTS525A or a different one? If RTS525A, I may be able to help you further if you send me the logs generated by the debug version of the kext. Also, it looks like it may be some problem with the card. Do other cards work? Does the card work on other OS? |
So I've done a bit of testing, and this is where I am so far: I have 4 SD cards:
All of these cards were bought from an authorized retailer (not Amazon), so likely to be genuine cards. All of them encounter I/O errors when writing random data or zeros with dd in macOS. I tried the same in Linux, and all cards write without I/O errors, and the data written reads back correctly byte-for-byte, so it looks like the cards and the reader are ok (XPS 15 9570). Output of
I'll collect debug logs tomorrow and get back to you. |
Here are some logs I collected while writing to two cards in different ways. Let me know if something doesn't make sense or if there's something else I can test.
In this case, Disk Utility gives this error: There is also an I/O error in the log there.
The logs for this are here, also with a couple of I/O errors: I had to truncate the log file in the middle to remove 98MB of repetitive logs, but I didn't see an error in the middle there, only at the end of the log. |
Thanks for the logs. I think you may be having this same problem, which you should be able to solve easily by setting the card reader as read/write in the BIOS (check this post). If that's not the case (assuming you are using Linux on the same laptop, Linux should fail too, unless it somehow bypasses the BIOS setting), are you sure you are not passing the -rtsx_ro boot flag? |
So you're thinking I've set the BIOS or the driver to read-only mode. I assure you I have not. I can write to an entire card from a file in Linux, then read back the result, and it will match byte-for-byte. The output of gdd (GNU dd installed via brew) above shows I could write 3.0GiB of a 16GB card before I hit an I/O error. If the card/BIOS/driver was set to read-only, I wouldn't be able to write 3GiB, and have it fail only then, right? It would fail at the beginning. I'm looking into this issue because I maintain a repo for an XPS 9570 (https://github.com/bavariancake/XPS9570-macOS), and one of the users created a PR for the SD card reader. I like to test things thoroughly, which is why I ended up here. To be frank, I took quite some time to test that each card works in Linux, and will fail consistently in macOS using this driver. If you're not interested in debugging the driver and reproducing issues on your end, that's fine, it's really no problem, I understand that it can suck to have random people lodge issues and complain. But please let me know if you're not interested in maintaining the driver, and I will pick it up from here. Now, if you are interested to getting to the bottom of the issue (as am I), could you test what happens when you write all zeros to an SD card with
Does this actually work for you? With more than one SD card? Thanks. |
I apologize. I missed the part that you are actually able to write some data.
My free time at this moment is very limited, so I'm afraid I won't be able to look into this for some time. By re-checking the logs, I see that the first (meaningful) error that you get is this:
Error 12 is Thank you very much for the thorough testing. |
@bavariancake, I have issued a new beta release that hopefully will fix your problem. I have not been able to reproduce it neither with release 2.2 nor with the new beta release. Since I believe this issue is due to DMA memory fragmentation, it should be more likely to happen on systems with low memory or after a long time of OS usage (whenever DMA region becomes fragmented). Just to confirm, can you please answer these two questions?
Please check the new beta release whenever you get some free time and let me know how it goes. It is posted here. |
I still see errors formatting with Disk Utility, and using dd seems to error out after anywhere from 2-14MB written, whereas before I could write a few GB before encountering an error. I saw that there were a few responses on InsanelyMac also, but just to add my experience.
32GB
This happens 5 minutes after a cold boot, i.e. right after I added the new kext, shutdown, then booted.
I found the file in the releases section of the repo, since it seems to be removed from InsanelyMac. I assume they're the same. |
Just wanted to mention that I know firsthand how difficult it can be to have people post issues but not resolve them. I've had my fair share of that maintaining my XPS 9570 repo, even though ultimately I'm glad I can help other people out. To that end, I'd like to offer a bug bounty of $200 to fix the I/O errors I reported in this issue. If someone provides an update to this repo that can pass my test with Maybe this is interesting to you @cholonam, just as a way to acknowledge the effort. If someone else wants to take this on, that's cool too. |
That's really weird.. are you getting error 12 (ENOMEM) again or other error? Error 60 (ETIMEDOUT) is not very meaningful since it's just a timeout meaning the card reader is not responding, probably because of bad error recovery from the OpenBSD driver. Just to make sure, I assume you are passing the -rtsx_mimic_linux boot parameter, and preventing sleep during the copy process somehow (i.e. caffeinate command). Let me know if otherwise. I was not able to reproduce your results neither before with a 1GB card, nor now with a 16GB card. Here is my test procedure:
Now, what's next? I appreciate the bounty, but since I am not able to reproduce the error, it will be almost impossible to solve. Hopefully somebody reads this and is willing to help. You can send me the debug log again and let's see if I can find something. You should not be getting error 12 now, probably you are getting an IO error and the driver is not doing error recovery properly so it just stops responding (lots of error 60, timeouts). This IO errors may be due to the cards, or your hardware, but definitely it's not common (since I am not getting them). Do you know of any other users having these error or are you the only one? If you are the only one, I'm afraid I'll have to close the issue as "not able to reproduce" (unless I see something I can fix in the logs). |
I'll test again and see which error codes I'm getting.
Yes, definitely passing
Yes, makes sense, since the input to
I'll do the same tests again and see what error codes I get, and I can verify that the driver gets the boot flag with a print statement. Which version should I be using? 2.2 or 2.3-beta? For some reason, I was getting I/O errors after writing just a few MB with 2.3-beta, but maybe the error codes are different. I'll get back to you. |
Use 2.3-beta. With 2.2 you may get memory errors. 2.3-beta should NOT give error 12, so I'd like to see which error it's giving you. |
I can confirm that I'm having a similar issue with 2.3-beta-debug on my XPS 9570. I seem to be able to read/dump just fine but the problem arrives when you try to format or use I'm using a Kingston 8GB micro sd card with an adapter. Ran the tests you mentioned in your last post @cholonam. Bootup and dumping a FAT32 formatet card
Worked just fine bootanddumpRevised.log Due to the size of the original file (200MB) I removed most of the logs from the dump since I did not see anything obvious other than raw read logs Writing urandom to sdcard
urandom write.txt Trying to format to ExFat Trying to format to ExFat - Using terminal
Running urandom write again after formating to exfat in windows
urandom write 2 after format.txt Trying to write imaged dumped in the first test back
For the sake of completeness, this is a list of the PCI devices with the sdcard reader on my XPS Hope this helps! Edit: I also have |
After more experimenting this seems to be an intermittent issue. I tried with another sdcard a Lexar 1GB SD and initially had the exact same problems with the other card but suddenly it started working after a few remounts. Logs attached are writing urandom data and working not the faulty state. logs lexar trimmed.txt Tried the card I used earlier in my last post and got other errors than previosly. Afterwards I tried formatting the card in windows with no problems Going back to the lexar car again on the hackintosh worked just fine and not been able to reproduce any errors with it again. |
Also tested a transcend 8GB microSD with an adapter and it is not detected at all (works fine in linux and windows on the xps) |
@stemnic @bavariancake Thanks for the efforts. Please wait until I upload a new beta with longer timeouts to continue testing. It will only take me some hours.. thanks! |
@stemnic @bavariancake I have uploaded a new beta version which allows for longer timeouts, with the hope that what you are getting are true timeout errors (that would be the best case scenario). Here are some instructions to test it when you get some time:
I have to say that it's likely that what you are getting are not really timeouts but just the card acting weird or just not responding. I did a test with this beta and I get very low timeouts. For example, for the STOP_TRANSMISSION command, which is the one giving the timeouts in @stemnic 's logs, the longest timeout I am getting is 7.3 ms (writing urandom to a 1GB TOSHIBA SD card). The kext is waiting up to 100 ms, but the original BSD code was waiting up to 1 sec. and I think Linux may be waiting up to 300 ms (not 100% sure though). With the rtsx_timeout_shift parameter you'll be waiting 800 ms, which should be more than enough.. However this driver is far from being complete. There are lots of corner cases it just does not handle, that's why some cards will work on Linux/Windows and not with this kext. If longer timeouts don't solve the issue, it's very likely these cards will never be compatible with this driver. |
Thanks for the update, seems like the card which was not detactable before now shows up. However I still have problems formating the kingston and trancent microSD cards. The Lexar as mentioned before apperares to work just fine. |
So it seems increasing the timeouts does not really help. What I can do is add some retry logic to the code, to see if that helps with IO errors. And for the timeouts after READ_BLOCK_MULTIPLE, I'll change the code a bit, because I see the Linux code sends a STOP_TRANSMISSION command even if READ_BLOCK_MULTIPLE multiple fails, but the OpenBSD driver (on which this kext is based) does not. It may be that the card needs the "STOP_TRANSMISSION" to go back to a "waiting for commands" state. I'll need one or two weekends to implement those changes, though, and I do not want to create false expectations: The fact that I can't reproduce these errors just makes it harder to fix, and I'll definitely be depending on your help for testing. You have to understand that despite all the testing, it may happen that these cards will never work with this driver. There are just too many corner cases that the Linux driver takes into account and this driver doesn't, so the most likely is that this driver only works with the "most well-behaved" cards. Let's hope for the best after I add the retry logic and STOP_TRANSMISSION logic. |
@stemnic @bavariancake I have just uploaded a new release with the changes mentioned above. I hope these changes can solve the problems you are having. Please test it when you find some time and let me know the results. |
Thanks for the update! Started testing yesterday, will get back to you when finished. |
OK, so after a lot of testing, here's what I found. Tests performedI started off with four SD cards I had flying around in my drawer (see above), and repeatedly did the following tests:
I've done each test across many reboots/cold boots, to rule out any kext loading issue on a particular boot or something similar. Test resultsEach card tested would either fail consistently, or would pass every test. The main difference between cards seems to be the age of the card, i.e. older and slower cards would fail consistently, and newer or more high-end cards would never fail. For example, an old Sandisk Ultra 16GB would always fail, but a Sandisk Extreme 16GB of the same vintage would not. Newer or faster cards, like the Sandisk Extreme Pro 64GB would read/write at a higher speed than before as well, around 13MB/s, which was an unexpected benefit. Looking at a reputable OEM retailer like B&H, I found that I couldn't even buy the older/slower cards anymore - even the cheapest Sandisk Ultra card feature 32GB with a UHS-I rating. While it would be nice if slow/old cards worked perfectly, it's not a priority since most new cards on the market would be fast enough. I suspect this points to a bug handling a busy state with slow cards, and I could mail you those old/slow cards if you're interested @cholonam. There are two more issues I found:
Only the last issue is somewhat of a problem - rebooting just to use the SD card slot is a bit of a hassle. The first problem can be ignored for now, i.e. tell the user not to do that 😊 ConclusionWhile it would be nice to support old/slow cards, this new driver is much more reliable than the prior version, and is noticeably faster than before, an unexpected benefit. While there are some quirks, the only concern is that it seems to not work at all on some occasions, requiring a reboot. Is this something you can reproduce @cholonam? If the "no SD card on some boot" problem can be fixed, I'd be happy to pay the bug bounty plus a bonus for your efforts. If you can't reproduce this problem, you still qualify for the bounty since the situation is much improved, but I'm curious if that last bit can be fixed. Let me know what you find. Thanks @cholonam! |
Thank you for the thorough testing @bavariancake. It's good to know that at least the issues seem card-specific and affect seemingly older/slower cards. I only have two cards: one old 1GB card, and a newer 32GB one), but for me the kext is working quite well. I only have one issue: sometimes (maybe one out of ten) the card is not detected on insert, but it's detected if I pull-off/insert again. I can live with that for now :) As for the other issues you mention:
This could be fixed, but I consider it very low priority, since the user is not expected to pull the card during a write operation, anyway. A different, more serious issue would be the laptop sleeping during a write operation, but I don't think that may happen (I do not use sleep, so never tested it).
This may be related to the issue I am also getting, only that I do see the card after pull-off/reinsert. It may be related to timeouts or error recovery. Anyway, given that at this moment my free time is very limited, and that at least the most critical issues are solved, I doubt I will be doing any further development on this kext for the time being, apart from merging pull requests, if I get any (for example, to improve stability with chips other than RTS525A). I do have a plan to port the Linux driver in the future (which is what I wanted to do from the beginning), but I definitely will not have time to start that task in the next one or two years, and by then I may have a different laptop/card reader... :( |
When formatting a Samsung Ultra 16GB SD card (the cheap kind floating in my drawer) I get I/O errors with Disk Utility every time:
dd has similar problems:
This happens with the latest release as well.
Can you reproduce this issue as well, or do other cards work for you?
The text was updated successfully, but these errors were encountered: